0

I have a small script that if you run it locally (windows) or on the server where I have deployed the code, it works fine.

It does 2 things, on the one hand I include some of its own classes and on the other hand I make a "fopen" of an html file in this way.

Include

include('Class/MysqlClass.php');
include('Class/UtilsClass.php');

Fopen

$handle=fopen("../Templates/email_esp.html","rb");

As I comment in local as in remote if I execute this script from the script directory it does not give problems of ROUTES

The problem is if I run it from cron with this statement

*/30 16-17 * * 1-6       su -c 'php /var/www/html/test_project/index.php' -s /bin/sh www-data 

Then it tells me that it does not find the classes. Instead if I put the relative path of the server type this if it works

include('/var/www/html/test_project/Class/MysqlClass.php');

And the same for fopen

$handle=fopen("/var/www/html/test_project/Templates/email_esp.html","rb");
ilernet2
  • 115
  • 1
  • 1
  • 7
  • 2
    Relative paths are based on where the file is being run from, not where the file exists. So if you run it while you're in test_project, you're fine. But if you try to run it from another directory such as `/`, then the relative paths no longer correct. – aynber Mar 31 '22 at 15:21
  • 1
    to add to @aynber you might also want to look at this: https://www.php.net/manual/en/ini.core.php#ini.include-path – ghatzhat Mar 31 '22 at 15:22
  • 1
    change to `su -c 'cd /var/www/html/test_project && php index.php'` as said by aynber its releated to the relative paths – Lawrence Cherone Mar 31 '22 at 16:03

0 Answers0