Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezruncronjobs.php
Go to the documentation of this file.
1 <?php
14 class eZRunCronjobs
15 {
20 static function runScript( $cli, $scriptFile )
21 {
22 $scriptMutex = new eZMutex( $scriptFile );
23 $lockTS = $scriptMutex->lockTS();
24 $runScript = false;
25 $maxTime = self::maxScriptExecutionTime();
26 if ( $lockTS === false )
27 {
28 if ( $scriptMutex->lock() )
29 {
30 $scriptMutex->setMeta( 'pid', getmypid() );
31 $runScript = true;
32 }
33 else
34 {
35 $cli->error( 'Failed to aquire cronjob part lock: ' . $scriptFile );
36 }
37 }
38 // If the cronjob part has been blocked for 2 * self::maxScriptExecutionTime(),
39 // force stealing of the cronjob part
40 else if ( $lockTS < time() - 2 * $maxTime )
41 {
42 $cli->output( 'Forcing to steal the mutex lock: ' . $scriptFile );
43 $runScript = eZRunCronjobs::stealMutex( $cli, $scriptMutex, true );
44 }
45 else if ( $lockTS < time() - $maxTime )
46 {
47 $cli->output( 'Trying to steal the mutex lock: ' . $scriptFile );
48 $runScript = eZRunCronjobs::stealMutex( $cli, $scriptMutex );
49 }
50 else
51 {
52 $cli->output( 'Cronjob part locked by other process: ' . $scriptMutex->meta( 'pid' ) );
53 }
54 if ( $runScript )
55 {
56 global $script;
57 global $isQuiet;
58 global $cronPart;
59 include( $scriptFile );
60 $scriptMutex->unlock();
61 }
62 }
63
70 static function maxScriptExecutionTime()
71 {
72 global $cronPart;
73 $cronjobIni = eZINI::instance( 'cronjob.ini' );
74
75 $scriptGroup = "CronjobPart-$cronPart";
76 if ( $cronPart !== false and $cronjobIni->hasVariable( $scriptGroup, 'MaxScriptExecutionTime' ) )
77 return $cronjobIni->variable( $scriptGroup, 'MaxScriptExecutionTime' );
78 else
79 return $cronjobIni->variable( 'CronjobSettings', 'MaxScriptExecutionTime' );
80 }
81
94 static function stealMutex( $cli, $scriptMutex, $force = false )
95 {
96 $cli->output( 'Stealing mutex. Old process has run too long.' );
97 $oldPid = $scriptMutex->meta( 'pid' );
98 if ( $force )
99 {
100 if ( is_numeric( $oldPid ) &&
101 $oldPid != 0 &&
102 function_exists( 'posix_kill' ) )
103 {
104 $cli->output( 'Killing process: ' . $oldPid );
105 posix_kill( $oldPid, 9 );
106 }
107 }
108 if ( $scriptMutex->steal( $force ) )
109 {
110 $scriptMutex->setMeta( 'pid', getmypid() );
111 return true;
112 }
113 else
114 {
115 $cli->error( 'Failed to steal cronjob part lock.' );
116 }
117 return false;
118 }
119 }
120
121 ?>
eZMutex
The class eZMutex provides a file based mutex. The mutex works across processes.
Definition: ezmutex.php:18
eZRunCronjobs
Definition: ezruncronjobs.php:15
eZRunCronjobs\stealMutex
static stealMutex( $cli, $scriptMutex, $force=false)
Definition: ezruncronjobs.php:94
eZRunCronjobs\runScript
static runScript( $cli, $scriptFile)
Definition: ezruncronjobs.php:20
eZRunCronjobs\maxScriptExecutionTime
static maxScriptExecutionTime()
Definition: ezruncronjobs.php:70
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.