/usr/share/php/Horde/Scheduler.php is in php-horde-scheduler 2.0.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | <?php
/**
* Horde_Scheduler
*
* @package Scheduler
*/
class Horde_Scheduler
{
/**
* Name of the sleep function.
*
* @var string
*/
protected $_sleep;
/**
* Adjustment factor to sleep in microseconds.
*
* @var integer
*/
protected $_sleep_adj;
/**
* Attempts to return a concrete Horde_Scheduler instance based on $driver.
*
* @param string $driver The type of concrete subclass to return.
* @param array $params A hash containing any additional configuration or
* connection parameters a subclass might need.
*
* @return Horde_Scheduler The newly created concrete instance.
* @throws Horde_Scheduler_Exception
*/
static public function factory($driver, $params = null)
{
$driver = basename($driver);
$class = 'Horde_Scheduler_' . $driver;
if (class_exists($class)) {
return new $class($params);
}
throw new Horde_Scheduler_Exception('Class definition of ' . $class . ' not found.');
}
/**
* Constructor.
*
* Figures out how we can best sleep with microsecond precision
* based on what platform we're running on.
*/
public function __construct()
{
if (!strncasecmp(PHP_OS, 'WIN', 3)) {
$this->_sleep = 'sleep';
$this->_sleep_adj = 1000000;
} else {
$this->_sleep = 'usleep';
$this->_sleep_adj = 1;
}
}
/**
* Main loop/action function.
*/
public function run()
{
}
/**
* Preserve the internal state of the scheduler object that we are
* passed, and save it to the Horde VFS backend. Horde_Scheduler
* objects should define __sleep() and __wakeup() serialization
* callbacks for anything that needs to be done at object
* serialization or deserialization - handling database
* connections, etc.
*
* @param string $id An id to uniquely identify this scheduler from
* others of the same class.
*
* @return boolean Success result.
*/
public function serialize($id = '')
{
try {
$vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create();
$vfs->writeData('.horde/scheduler', Horde_String::lower(get_class($this)) . $id, serialize($this), true);
return true;
} catch (Horde_Vfs_Exception $e) {
Horde::logMessage($e, 'ERR');
return false;
}
}
/**
* Restore a Horde_Scheduler object from the cache.
*
* @param string $class The name of the object to restore.
* @param string $id An id to uniquely identify this
* scheduler from others of the same class.
* @param boolean $autosave Automatically store (serialize) the returned
* object at script shutdown.
*
* @see Horde_Scheduler::serialize()
*/
public function unserialize($class, $id = '', $autosave = true)
{
/* Need a lowercase version of the classname, and a default instance of
* the scheduler object in case we can't retrieve one. */
$scheduler = new $class;
try {
$vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create();
$data = $vfs->read('.horde/scheduler', $class . $id);
if ($tmp = @unserialize($data)) {
$scheduler = $tmp;
}
} catch (Horde_Vfs_Exception $e) {
Horde::logMessage($e, 'ERR');
}
if ($autosave) {
register_shutdown_function(array($scheduler, 'serialize'));
}
return $scheduler;
}
/**
* Platform-independant sleep $msec microseconds.
*
* @param integer $msec Microseconds to sleep.
*/
public function sleep($msec)
{
call_user_func($this->_sleep, $msec / $this->_sleep_adj);
}
}
|