Cron having trouble running PHP file

Asked

Viewed 193 times

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?

1 answer

1

An option would be to change the CRON command to cd /home/sitebr/public_html/ && /usr/local/bin/php ./Model/Routines/Rotina1.php

With this, the "execution location of the script" is changed to be the same used by the web server: /home/sitebr/public_html/.

  • Remembering that it would be more useful if people voting against left a comment. So, not only the AR, but also the AP could know what’s wrong.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.