Re: Script Multitasking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, October 29, 2005 3:57 pm, Martin Zvarík wrote:
> I have a file, which I run using command line. The file I am running,
> runs several files using passthru().
> What I realise is, that it runs each file in sequence and waits for
> its
> result.
> I need to run all files at once and they don't have to return the
> result
> to the main file. How do I do this?

Couple Options:

Change your script to accept a single filename from the command line
($argv) and then run several of that script from command line in the
background:
php -q singlefileprocess.php datafile1.txt &
php -q singlefileprocess.php datafile2.txt &
php -q singlefileprocess.php datafile3.txt &


http://php.net/pcntl
This basically would be the same (sort of) as just running multiple
copies of your PHP script, one for each file, but keeps your script
able to process multiple files...
Not sure it's worth the effort, but there it is.

You could also use http://php.net/exec to have PHP fire up more PHP
scripts in the background:
<?php
  //loop through $filename
  exec("/full/path/to/php -q processonefile.php $filename &", $output,
$error);
  if ($error) echo "OS Error: $error\n";
  echo implode("", $output);
  if ($error) exit;
?>

Note that in all cases, not only with the results most likely not
return to the main file, they'll be reading the files in parallel and
doing whatever to them... Be sure that this won't affect other parts
of the application.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux