Page 1 of 1

How to get PHP to exec() a PHP Script??

Posted: Tue Aug 06, 2002 12:16 am
by DesignerSMS
Hi Everyone,

I am hoping that this is a simple problem with a simple solution otherwise, I have a lot of work ahead of me.

The platform I am running on is Win2K with IIS 5.0 and PHP 4.1.1.

Safe mode is not enabled.

I am writing a script that, during the course of execution needs to execute another script that will then run in the background and complete execution without the user having to wait for it to complete.

The script looks something like this:

Code: Select all

<?php
$cmd = "C:/php/php.exe -q script.php >> outfile";
?>
where script.php is something simple like:

Code: Select all

<?php
echo "Hello World!\n";
?>
I have tried to run this but it just makes PHP hang. I have tried other executable files and plain batch files and these all seem to work. It only appears to be when I am executing a PHP script from a PHP script.

I thank anyone who can answer this question as it has me stumped.

:: Kondro ::

Posted: Tue Aug 06, 2002 9:37 am
by hob_goblin
have you tried...

http://www.php.net/include ?

eval

Posted: Tue Aug 06, 2002 11:08 am
by gte604j
have you tried eval?

sorry i have never used php on a windows machine, but if i need to evaluate something as php code and get it run i use eval.

Posted: Tue Aug 06, 2002 1:29 pm
by volka
eval and include are nice.

If you insist in spawning try to force a new shell to be executed
$cmd = 'c:/winnt/system32/cmd.exe /C C:/php/php.exe -q script.php >> outfile';
or try php-cli.exe if available

Haven't tried this - only a guess

Posted: Tue Aug 06, 2002 6:45 pm
by DesignerSMS
Hi,

Thanks for the suggestions.

Unfortunately, I have found none of these things to work.

Including a PHP file is not an option as I need it to execute in the background (as it will be processing a lot of information and I need an instant response to the user, even in the background process has not been completed).

I seem to be able to execute any other process but another PHP process.

What is the php-cli.exe application that was talked about above?

Thank you again for your time.

:: Kondro ::

Posted: Tue Aug 06, 2002 8:34 pm
by volka
I think that cli is command line interface and php.exe cannot execute scripts from command line.
php-cli.exe is in the .zip-distribution of PHP.

Posted: Tue Aug 06, 2002 8:50 pm
by DesignerSMS
Volka, thanks for pointing me in the direction of php-cli.exe.

Now for another interesting problem.

While the manual pages say that all you have to do to get the process to operate in the background is to redirect its stdout somewhere else, the process will not drop into the background.

If this was a Linux system this would be easy because I could just drop the "&" symbol at the end of the command but, because this is Win2K based, I cannot.

Does anyone know how to execute a background process using PHP in Win2K?

Thanks for looking.

:: Wayne ::

Posted: Tue Aug 06, 2002 11:03 pm
by volka
maybe

Code: Select all

$cmd = "start C:\\php\\php-cli.exe -q script.php >> outfile";
or

Code: Select all

$cmd = "cmd /C start C:\\php\\php-cli.exe -q script.php >> outfile";
will do - maybe not. I don't know. Neither if nor where the new window will be created :roll: