PHP passthru and exec problems on new server

dmccull2000
dmccull2000 used Ask the Experts™
on
I am having an issue. I am upgrading a web server with a new server. The previous server used IIS6, PHP, with ISAPI and works fine. On the new server I have purchased a new server, installed PHP but the newest version of PHP now wants CGI. No problem, set this all up and the site works except for areas I use passthru to modify PDFs. Started testing and it appears passthru or exec are not doing nothing.

Here is a test file I created.

<?php

echo "TEST PDFTK<br>";


$fname = $uploaddir.$storybookID.".txt";
$command = "pdftk D:\book\Images\Originals\SASAKJ5FT.pdf dump_data output d:\book\Images\Originals\SASAKJ5FT.txt";
echo "command ".$command."<br>";
passthru($command); //run the command
      
echo $test;


?>
It should create a text file from the document, but from php it does nothing. From command line on the server it works fine. Some of the items I have tried was changing permission on the site to read write execute on the website thinking it may not have permissions to create the file, but this did not work.

Checked the PHP.ini file and I am not running in safe mode.

Not sure what else to check, but will continue troubleshooting.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I also tried changing the path credentials for IIS to the administrator account. This also had no effect.
Check in the php.ini file to see if this function is listed under 'disable_functions' or do

<?php
phpinfo();
?>

and scan for 'disable_functions'. It is quite common to have two php.ini files - one for command line use and one for web use.

http://uk.php.net/manual/en/ini.core.php#ini.disable-functions

Author

Commented:
I checked this, here is the setting in the ini file disable_functions =
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

OK - passthru is not disabled.

You say it works on the command line, is that because the D: drive is already defined? Can the webserver see/access the D: drive? I guess what I am asking here is when passthru executes does it get a fresh copy of some default shell that may not have a D: drive defined.

Is D: mapped from elsewhere or is it a physical device? Does the passthru work for the C: drive if you try executing a test using C: ?

Author

Commented:
You were close and got me on the right path. d:\PHP is in my path, but PHP is not seeing it as a path. If I added d:\php\pdftk instead of just pdftk it worked, though in the command line it would allow for pdftk since it could access it as part of the path.

In order to keep from having to reprogram the site, I added pdftk.exe to the c:\windows directory.
Great stuff. You should be aware that PHP paths always use '/' rather than '\' EVEN WHEN ON WINDOWS machines. PHP converts the separators. This stops the problems of using '\' inside double quoted strings as the '\' is a PHP escape character. So.

$path = "c:/path/to/folder";    and
$path = "c:\\path\\to\\folder"  and
$path = 'c:\path\to\folder';

are all equivalent. The difference in the last is because with single quotes the escaping does not occur whereas in double quotes \\ means \

I hope that helps and I am glad your problem is sorted out.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial