0
I have a problem executing my tasks in Cron.
When I access the script to be run by the browser it works normally, but when it is run by cron, I get the following error:
PHP Warning: require_once(../../Config.php): failed to open stream: No such file or directory in /home/sitebr/public_html/Model/Routines/Pattern.php on line 8
PHP Fatal error: require_once(): Failed opening required '../../Config.php' (include_path='.:/opt/cpanel/ea-php72/root/usr/share/pear') in /home/sitebr/public_html/Model/Routines/Pattern.php on line 8
I’m a beginner with Cron, so maybe it’s something simple that I don’t know how it works.
Now explaining better the part of the files, I have a folder structure more or less like this:
|-public_html
|-Model
|-Routines
|-Pattern.php
|-Rotina1.php
|-Rotina2.php
|-Rotina3.php
|-Controller
|-AutoLoad.php
|-Config.php
All routines make one require_once
in the archive Pattern.php
which contains default settings that will be important for all of them, follows file content Pattern.php
:
<?php
error_reporting (E_ALL);
ini_set ("log_errors","1");
ini_set ("error_log",$_SERVER['DOCUMENT_ROOT']."/ErroSistem.txt");
ini_set ("display_errors" ,"0");
ini_set('max_execution_time', 100);
require_once("../../Config.php");
require_once("../../Controller/AutoLoad.php");
The problem is in those two require_once
within the Pattern.php
, it fails to find the files, but following the folder structure it is ok and testing via browser is also ok.
The require_once
that has inside the routines, calling the file Pattern.php
works well, shows no error even by Cron.
The routines were configured by cPanel, in the graphical interface, using the command:
/usr/local/bin/php /home/sitebr/public_html/Model/Routines/Rotina1.php
Does anyone have any idea what it is?
Just do it to make sure it works
require_once(__DIR__ . "/../../Config.php");
, the__DIR__
will pick up from the path of the script that runs, even if it is included, if run straight .. / it will pick up from the script called and not from the "included" (chance the call .. / be inside the included).– Guilherme Nascimento
This answers your question? fopen(/home/loyusgyp/public_html/logs/log_jurosefine/log_2020-02-02_18-00-01.txt): failed to open stream: No such file or directory in (Cpanel)
– tvdias
@Guilhermenascimento I managed to settle with the DIR, I focused so much on cron and missed the basics of php kkkk I made this change and a few more on Autoload and everything working now, thank you.
– Gabriel Queiroz Schicora
@tvdias responds yes, had not been able to find this post before, but although I have solved with the tip of the friend above, the post also helped.
– Gabriel Queiroz Schicora