PHP Classes

it doesn't work in production enviroment

Recommend this page to a friend!

      PHP Cron Job Manager Script  >  All threads  >  it doesn't work in production enviroment  >  (Un) Subscribe thread alerts  
Subject:it doesn't work in production enviroment
Summary:it doesn't work in production enviroment
Messages:2
Author:behnamy
Date:2015-09-25 19:25:31
 

  1. it doesn't work in production enviroment   Reply   Report abuse  
Picture of behnamy behnamy - 2015-09-25 19:25:31
Hi martin, I created my script some weeks ago and used your package in it, and my developing environment was windows, So I couldn't check if your codes are working correctly or not, and I was hoping that it will work in my production environment(Centos 7 with Directadmin).
But today I tested it and it doesn't work in my server, and when I add it to cron jobs, an email sends to me to that some functions are disabled in my server!
I thought it is because of some functions like pcntl that you used in your codes, so I enabled pcntl module, but it is not working yet.
I think the problem is in these below lines:

foreach ($jobs as $job) {
$pid = pcntl_fork();
if (! $pid) {
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$process = proc_open($job['cmd'], $descriptorspec, $pipes);
if (is_resource($process)) {
echo $procout = stream_get_contents($pipes[1]);
echo $procerror = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
$return_value = proc_close($process);
}
break;
}
}

_____________________________
would you tell me what's wrong with your codes/my server or is it possible that you add another way for execute jobs instead of pcntl/proc functions? for example check if pcntl function is not available then executing jobs with another method!

  2. Re: it doesn't work in production enviroment   Reply   Report abuse  
Picture of Martin Pircher Martin Pircher - 2015-09-29 23:28:51 - In reply to message 1 from behnamy
Hi behnamy,

the class itself should work on any OS (thus there's no requirement for the pcntl extension in composer.json), however the provided sample for an executor PHP script does require POSIX process control (as stated in the readme.md).

However, you should be able take the sample executor and replace the execution part (lines 56 to 72) with any code that executes an external program (i.e. 'echo shell_exec(escapeshellcmd($job['cmd']));' or 'pclose(popen("start /B ". $job['cmd'], "r"));')

Beware if the execution call is blocking the executor PHP script until it finished its execution you might miss other execution times.

wbr,
Martin