1

So basically i want to run script that will make around 15k pdf files, and it needs to be done from shell because of php max_timeout...

Server: Ubuntu 10.04.1 PHP : 5.3.2-1ubuntu4.5

So what i currently tried:

function run_in_background($Command){
    $ps = shell_exec("nohup php5 $Command > /dev/null 2> /dev/null & echo $!");
    return $ps;
}

$ok = run_in_background('/var/www/custom/web/public/make_pdf.php');

if(!empty($ok))
    var_dump($ok);
else
    exit('Fail');

And after that i go to ssh console and do ps $ps and in response i get headers only with no info - witch means process is not running...

How can i do this so it works?

arma
  • 4,084
  • 10
  • 48
  • 63
  • 1
    try without `echo $!` or ending with `&`. If you want to run 2 proccess 'inline', use `&&` instead of a simple `&`. example: `nohup php5 $Command > /dev/null 2> /dev/null && echo $! &` – jotapdiez May 06 '11 at 13:22
  • in this case $ok is empty and script returns me Fail. – arma May 06 '11 at 13:27
  • @arma how did you know if the process ended with an error? try placing output in a file. – jotapdiez May 06 '11 at 13:31
  • @jotapdiez i don't know that all i know it did't return PID of the process. Ok how you output everything in file? – arma May 06 '11 at 13:34
  • @arma just do `nohup php5 $Command > command_stout.txt 2> command_stderr.txt && echo $! &` and check both files – jotapdiez May 06 '11 at 13:36
  • Well it gives me fatal error on require_once, thats because my path is build using global `$_SERVER['DOCUMENT_ROOT']`. – arma May 06 '11 at 13:45
  • @jotapdiez - Ok i made another init file using absalute paths without global variables. And now process is running and i can see it in my shh console. :D Thanks, for assistance. If you care to post it as answer i'll accept it. – arma May 06 '11 at 13:50

2 Answers2

1

Try to put a & after Command :

$ps = shell_exec("nohup php5 $Command & > /dev/null 2> /dev/null & echo $!");
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
1

Try without echo $! or ending with &. If you want to run 2 proccess 'inline', use && instead of a simple &.

Example: nohup php5 $Command > /dev/null 2> /dev/null && echo $! &

To check if the proccess end with error do this:

nohup php5 $Command > command_stout.txt 2> command_stderr.txt && echo $! &

jotapdiez
  • 1,456
  • 13
  • 28