I've got a few php pages which after upgrading to Joomla 4 didn't work, I have managed to get them working properly if I manually open them in the browser but they fail when run as a cron job.
I am using PHP 8.0
I am sure I must be missing something simple and hope that someone can give me some pointers.
I've only included the first part of the code which contains the Joomla references as Stackoverflow didn't like all the code included
$length_to_fetch_minutes = 10;
define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
// instantiate application
// $app = JFactory::getApplication('site');
// Set the application as global app
// \Joomla\CMS\Factory::$application = $app;
// $app->createExtensionNamespaceMap();
// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();
$container->alias('session.web', 'session.web.site')
->alias('session', 'session.web.site')
->alias('JSession', 'session.web.site')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
// Instantiate the application.
$app = $container->get(\Joomla\CMS\Application\SiteApplication::class);
// Set the application as global app
\Joomla\CMS\Factory::$application = $app;
// database connection
$dbj = JFactory::getDbo();
JLoader::discover('Sim', JPATH_LIBRARIES . '/sim');
The error is:
Blockquote RuntimeException {#168 #message: "Could not parse the requested URI http:///home/ruralde1/example.com/iot2/data.php" #code: 0 #file: "./example.com/iot2/libraries/vendor/joomla/uri/src/AbstractUri.php" #line: 373 trace: { ./example.com/iot2/libraries/vendor/joomla/uri/src/AbstractUri.php:373 { …} ./example.com/iot2/libraries/src/Uri/Uri.php:290 { Joomla\CMS\Uri\Uri->parse($uri) › { › return parent::parse($uri); › } arguments: { $uri: "http:///home/ruralde1/example.com/iot2/data.php" } }