Skip to content

Commit 10a0525

Browse files
authored
Merge pull request #180 from dereuromark/bugfix/timeout
PHP timeout fix.
2 parents d759f1c + 1edb516 commit 10a0525

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

config/app_queue.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
// seconds of running time after which the worker will terminate (0 = unlimited)
2323
'workermaxruntime' => 120,
2424

25+
// seconds of running time after which the PHP process will terminate, null uses workermaxruntime * 100
26+
'workertimeout' => null,
27+
2528
// minimum time (in seconds) which a task remains in the database before being cleaned up.
2629
'cleanuptimeout' => 3600,
2730

src/Shell/QueueShell.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ public function runworker() {
145145
$types = $this->_stringToArray($this->param('type'));
146146

147147
while (!$this->_exit) {
148-
// make sure accidental overriding isnt possible
149-
set_time_limit(0);
148+
$this->_setPhpTimeout();
150149

151150
try {
152151
$this->_updatePid($pid);
@@ -633,4 +632,18 @@ protected function _stringToArray($param) {
633632
return array_filter($array);
634633
}
635634

635+
/**
636+
* Makes sure accidental overriding isn't possible, uses workermaxruntime times 100 by default.
637+
*
638+
* @return void
639+
*/
640+
protected function _setPhpTimeout() {
641+
$timeLimit = (int)Configure::read('Queue.workermaxruntime') * 100;
642+
if (Configure::read('Queue.workertimeout') !== null) {
643+
$timeLimit = (int)Configure::read('Queue.workertimeout');
644+
}
645+
646+
set_time_limit($timeLimit);
647+
}
648+
636649
}

0 commit comments

Comments
 (0)