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

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
User avatar
DesignerSMS
Forum Newbie
Posts: 17
Joined: Tue Aug 06, 2002 12:16 am
Location: Gold Coast, Australia

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

Post 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 ::
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

have you tried...

http://www.php.net/include ?
gte604j
Forum Newbie
Posts: 4
Joined: Tue Aug 06, 2002 10:58 am

eval

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
DesignerSMS
Forum Newbie
Posts: 17
Joined: Tue Aug 06, 2002 12:16 am
Location: Gold Coast, Australia

Post 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 ::
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
DesignerSMS
Forum Newbie
Posts: 17
Joined: Tue Aug 06, 2002 12:16 am
Location: Gold Coast, Australia

Post 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 ::
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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:
Post Reply