Page 1 of 1

A hard one...

Posted: Wed Jul 27, 2005 1:19 pm
by tores
Hi

I'm making a php-script that dumpes the contents of a database and then gzip the dumped file... The script runs as a standalone CLI.
The dump is made with mysqldump, and works as expected through system()...
The gzip command however doens't... Well, actually it does if I run the script from DOS, but not if called from php (with shell_exec).

The gzip command:

Code: Select all

$last_line = system('gzip -fv9 backup\polyfemos_27_07_2005_backup.sql', $result);
I've tried writing the current working directory and the values of $last_line and $result to file.
When called from DOS the script outputs the following:

Code: Select all

cwd=C:\Program Files\Apache\htdocs\plan
result=0
last_line=
And when called via shell_exec:

Code: Select all

cwd=c:\program files\Apache\htdocs\plan
result=1
last_line=
When looking into the gzip manual i found that a return-value of 1 means that gzip returned with an error. 0 is okey.
My only guess for what's wrong is the current working directory. But the only difference here is that Program Files is spelled witg lowercase letters in the later file output...

My hair is turning gray over this, so please give me hint if you got a clue...

regards tores

Posted: Wed Jul 27, 2005 2:01 pm
by tores
By redirecting stderr to stdout I where able to get the errormsg...
'gzip' is not recognized as an internal or external command,
operable program or batch file.
For some reason the gzip directory isn't recognized in the PATH variable when the script is called via shell_exec... mysqldump is found however... How strange is that :?

Posted: Wed Jul 27, 2005 2:15 pm
by nielsene
Somewhere in the php.ini file is the list of the program execution path. It is different than the user's path for security reasons.

Posted: Wed Jul 27, 2005 2:35 pm
by tores
When looking into $_ENV['Path'] I found the reason. When called from the command line this entry contains all members of the PATH variable. When called with shell_exec it contains all members except the one telling where to find gzip :?
Is it the settings in php.ini that causes this?

Posted: Wed Jul 27, 2005 2:57 pm
by tores
I ended up moving gzip.exe to the system folder. I guess something in the gzip-folder excluded it from the PATH in some cases. How knows... "The Truth Is Out There" :wink: At least it's working now...

Posted: Wed Jul 27, 2005 2:59 pm
by timvw
When using exec etc i usually provide the full path..

Just in case someone would be able to place a 'custom' zip.exe in a directory that is earlier in the path ;)