php - shell_exec results in 404 error before command has completed -


i not experienced, use in troubleshooting this... kinda stuck right now. :-( in advance:

i developing module ecommerce platform. have script @ www.mystore.com/modules/mymodule/myscript.php

the myscript.php code in it:

$command = '/do/some/process/ -make_log_files'; echo shell_exec($command); //here stuff log file, know process has completed. 

all works fine in theory. process initiated $command start , completes after while (i can tell log files creates). should noted there no evidence script.php accesses of mystore files. logged message in mystores fundamental include files, , see message if exit() before shell_exec().

because process slow , takes long time finish up, when navigate browser www.mystore.com/modules/mymodule/myscript.php browser says "waiting mystore.com ..." , keeps showing it's loading animation.

after while show 404 page of mystore.


edit: all following stuff useless in case , found better solution.

i have added these things beginning of script.php try prevent happening:

ini_set('output_buffering', 'off'); ini_set('zlib.output_compression', false); while (@ob_end_flush()); ini_set('implicit_flush', true); ob_implicit_flush(true); header("content-type: text/plain"); header('cache-control: no-cache');  http_response_code(200); for($i = 0; $i < 1000; $i++) {     echo ' '; //echo 1000 whitespaces } ob_flush(); flush(); 

instead of shell_exec have tried use these other commands, either same result, or printing , empty array or similar before process has completed.

$process = (popen($command, "r")); echo "'$process '; " . gettype($process ) . "\n"; $read = fread($process , 2096); echo $read; pclose($process ); 

and

exec($call,$output); print_r($output); 

and

passthru($call); 

none did better.

edit: turns out, because i'm running on fastcgi, whole "no buffer send data straight browser" won't work.


if calling script result in 404 after amount of time, how ever make sure process has completed?

i should note command not end >/dev/null &. intentionally not putting in background.

also have tried script , changed parameters of command process done quick. works expected then.

i realize there other solutions (cron job or javascript check log files) if i want script wait process complete? not possible?


edit:

thanks drew010's helpful comments realized following:

  • checking log files showed had 500 error, not 404
  • disabling htaccess mystore.com made show 500
  • the error coming after approx. 2 minutes, caused cgi server timeout
  • i decided rather try , mess cgi settings run script directly through command line:

call.php:

exec(php home/usr/mystore.com/modules/mymodule/myscript.php > /dev/null 2>&1 &'); echo 'all things set in motion, go!'; 

and can go www.mystore.com/modules/mymodule/call.php run script in background! , once script in background there no timeouts , php code patiently waits slow process done , rest of it's job. :-)

the 404 error result of sort of timeout being reached.

it common web servers have cgi timeout terminate request if not receive response cgi backend within amount of time.

since script running time timeout reached terminated connection.

in past i've seen happen , website shows 404 when in server logs see 500 error indicating server didn't receive response backend within timeout period.

if running task terminal possible, better option, or can try increasing timeouts. in case, cgi timeout higher php max_execution_time directive in sync.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -