View Full Version : system call exection
dillieo
01-09-2003, 07:44 PM
Greets all,
If I make a system() or exec() call in PHP, does the script automatically wait for the system call to finish, or do I need to do some kind of $SIG{'CHLD'} = sub { wait }; call like I would in Perl? Please let me know ASAP. Thanks!
firepages
01-10-2003, 02:57 AM
Hi, yes it tends to hang around waiting for the process to finish, you can try virtual() for PERL scripts but best bet is probably popen() on win32 which is supposed to run the command in a seperate process... eg
<?
$yaks=popen("c:/php/php -q -f c:/scripts/file.php");
pclose($yaks);
?>
but it depends on what exactly you want to do?
(on *NIX you could also look at the pctl functions.)
dillieo
01-10-2003, 04:07 PM
(on *NIX you could also look at the pctl functions.)but it depends on what exactly you want to do?
Thanks for your repsonse...
I thin I might need that option. I'm running the script from command line only that is doing some text parsing. I need to call an API (command line based as well) that will actually do the backup and generate a text file (non-PHP function) and then when that function is done, I will grab the file it generated and work with it. So I can't just call the function and keep going, I must wait until the file is done being generated, and that can take from 2 seconds to 2 minutes since its grabbing data from a database.
Any additional thoughts?
firepages
01-10-2003, 11:43 PM
Hi, if you need to wait for the script to finish you may have to<?set_time_limit($seconds);?> to avoid a script timeout, other than that you should be able to continue as normal...
eg - on my aging system 'tree' took about 2 minutes to run the first time...
<?
set_time_limit(360);
exec("tree > test.txt",$yaks);
if(is_file('test.txt')){
echo "ok";
//print_r($yaks);//here $yaks is an array//
}
?>
you could also get your scripts to return a value which would show up in $yaks in some form or another.
dillieo
01-12-2003, 08:40 PM
Thanks for the help! Everything has been working fine so far, but that timeout will definitely be needed, especially when I star working with 50,000 records at a time. I'd love to show you the finished script (nothing fancy really), but its on an internal network 8^D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.