From reading the source code it's not a million miles from JApplicationCli, which works perfectly, but there must be some secret sauce to be applied to get it working.
Here's my simple test programme:
Code: Select all
<?php
const _JEXEC = 1;
if (file_exists(dirname(__DIR__) . '../../defines.php'))
require_once dirname(__DIR__) . '../../defines.php';
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__) . "/../..");
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
class LaunchCLI extends JApplicationCli
{
public function doExecute()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*) AS count')->from($db->quoteName('#__content'));
$db->setQuery($query);
$result = $db->loadObject();
$this->out("pages: " . $result->count);
}
}
class LaunchDaemon extends JApplicationDaemon
{
public $name='test';
public function doExecute()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*) AS count')->from($db->quoteName('#__content'));
$db->setQuery($query);
$result = $db->loadObject();
$this->out("pages: " . $result->count);
}
}
$options = getopt("d");
try {
if (array_key_exists('d', $options))
JApplicationDaemon::getInstance('LaunchDaemon')->execute();
else
JApplicationCli::getInstance('LaunchCLI')->execute();
}
catch (Exception $e){
echo $e->getMessage() . "\n";
}
?>
Code: Select all
$ php test.php
pages: 1
$
Code: Select all
$ php test.php -d
PHP Warning: pcntl_signal(): Specified handler "DaemonApplication::signal" is not callable (class 'DaemonApplication' not found) in /var/www/game.conlucra.com/public_html/libraries/src/Application/DaemonApplication.php on line 886
Any ideas gratefully received
David