Reputation: 1514
I've a problem in running a continous background process in which the parent initiate 2 or 3 child process then end itself, child processes have heavy computation so they will take alot of time.
I'm using exec command to start the process but don't know it doesn't start neither it generates any error(error reporting is on,E_ALL and display_errors)
Here is how I'm trying to do this
error_reporting(E_ALL);
ini_set('display_errors',1);
$output = '';
$dir = dirname(__FILE__).'/';
//$cmd = "nohup php {$dir}/background-service.php > /dev/null & echo $!";
$cmd = "nohup php background-service.php >/dev/null 2>&1 &";
exec($cmd );
background-service.php
<?php
ini_set('max_execution_time', 0);
ini_set('display_errors',1);
file_put_contents('a'.time().'.txt',"this is the test code");
?>
when I hit the file directly it generates a file, but not with exec, I've tested exec is enabled(ubuntu server)
if ( $safe_mode = ini_get( 'safe_mode' ) && strtolower( $safe_mode ) != 'off' )
{
echo 'Safe Mode is Disabled';
}
else
echo 'Safe Mode is Enabled<br/>';
if ( in_array( 'exec', array_map( 'trim', explode( ',', ini_get( 'disable_functions' ) ) ) ) )
{
echo 'exec is Disabled';
}
else
echo 'exec is Enabled<br/>';
Someone please tell me where I'm wrong in it, how can I detect if its disabled by server
Thanks
Upvotes: 0
Views: 1592
Reputation: 3760
Check this safe-mode-exec-dir and You don't need to set max execution time for command line scripts by default they have no limit.
Upvotes: 1
Reputation: 783
This is just a guess, but try using the full path of anything you're executing. Running the command from a shell may work for YOUR user account, but keep in mind the process is running as the apache user.
Also, using exec() with additional parameters may be useful for you. The third parameter can specify where to store the return status of the command (probably helping you figure this out). (courtesy the PHP manual)
Upvotes: 1