|
behnamy - 2015-09-27 17:54:46
Hi, I couldn't enable pcntl, so I changed that part of code to below one:
foreach ($jobs as $job) {
if ((function_exists('pcntl_fork')) AND (function_exists('proc_open')) AND (function_exists('stream_get_contents')) AND (function_exists('proc_close'))) {
$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;
}
}
else{
// shell_exec('nohup '.$job['cmd'].' > /dev/null &');
exec('php -q '.$job['cmd']);
}
}
_______________________
And each of scripts in $jobs executes, but the lastexecution filed of DB doesn't update. and all jobs execute each time of calling this executor.
How can I fix this problem?
Martin Pircher - 2015-09-29 23:34:48 - In reply to message 1 from behnamy
Hi behnamy,
does your executed PHP script properly call the setLock()/releaseLock() methods?
As you see in the samplejob.cli.php skeleton the called PHP script must run those methods - which are setting the lastexecution date (private setLockDB()).
The target PHP script must take care of other things too - i.e. schedule next run with scheduleJob() and if needed checking the lock status to prevent parallel runs.
And: it's not possible to manage execution of scripts or programs other than PHP (i.e. you can't directly manage call of binaries, you would need to write a PHP wrapper script).
wbr,
Martin
behnamy - 2015-09-30 06:02:12 - In reply to message 2 from Martin Pircher
this field in DB was 0000:00:000 before any exucatuon(after adding jobs) and it is zero now after changing the above code. what should I do?
______________________________
As you see in the samplejob.cli.php skeleton the called PHP script must run those methods - which are setting the lastexecution date (private setLockDB()).
Do I need samplejob.cli.php anymore? I used it first when I wanted to add some jobs. and now I execute sample/executor.cron.php from my cron-job part of my webhosting control panel. And this sample/executor.cron.php requires src/executor.php
Martin Pircher - 2015-10-02 18:34:33 - In reply to message 3 from behnamy
You don't need samplejob.cli.php at all - it's just a skeleton you can take as template for your PHP based cron scheduled files.
Question 1: Does your script include calls to the setLock()/releaseLock() methods? The lastexecution timestamp won't get updated if your script doesn't use those methods...
Question 2: if you schedule the sample script does the lastexecution timestamp gets updated?
Example:
You scheduled a script /var/home/youruser/cron-scripts/email.php.
The email.php needs to create a cronjob object:
$job = new CronJob('EmailJob', $dbcfg);
It's required to create a lock (this also updates the lastexecution timestamp):
$status = $job->setLock();
At the end of your script you need to release the lock (this also updates the lastexecution timestamp again):
$status = $job->releaseLock()
If you take care of locking or not is optional and depends on your scripts purpose (code needs to be placed before setting the lock):
$status = $job->getStatus()
if ($status['locked'] == 'y') {
throw new Exception('ERROR: Previous MailJob still running!?');
}
behnamy - 2015-10-02 18:54:52 - In reply to message 4 from Martin Pircher
aha, I understood! you mean I need lastexecution field only if I need using Lock in my processes! No I don't need it, but I thought that this field will update everytime I run each of my scripts by your executer! I don't use releasLock/lock methods in my scripts, all of my scripts don't use your methods. just your executor execute my files.
_________________
I could finally enable pcntl, and now I'm using your package, but now I faced a new problem! executing scripts with your package(because of pcntl_fork) needs 755 as permission(instead of 644, the default permission in webhostings). And it seems that I need to change the permission of all files that are included/required in the file that I'm going to execute it. So I need to change the permission of the whole folder of my script to 755 and I think this will be dangerous. Is there anything I can do for this problem?
______
would you give me your email that I can contact you directly? because it seems that you don't come here too much.
Martin Pircher - 2015-10-05 11:19:41 - In reply to message 5 from behnamy
And there's your problem...
> I don't use releasLock/lock methods in my scripts
> all of my scripts don't use your methods.
Once again, you MUST call the lock() methods otherwise it won't work. This is required, not optional.
So take the skeleton and replace lines 68-71 ("here goes the jobcode...") with your code.
|