A hard one...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

A hard one...

Post 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
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post 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 :?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post 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?
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post 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...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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 ;)
Post Reply