Answer the question
In order to leave comments, you need to log in
How to setup cron to run php script?
Hello everyone, I ran into a problem with executing a script using cron.
test.php
<?php
define('ROOT', $_SERVER['DOCUMENT_ROOT']);
require_once ROOT . '/core/db.php';
...
/usr/bin/php /var/www/user/data/www/domain/modules/test.php
PHP Warning: require_once(/core/DB.php): failed to open stream: No such file or directory in /var/www/user/data/www/domain.ru/modules/test.php on line 3
PHP Fatal error : require_once(): Failed opening required '/core/DB.php' (include_path='.:/usr/share/php') in /var/www/user/data/www/domain.ru/modules/test. php line 3
Answer the question
In order to leave comments, you need to log in
$_SERVER['DOCUMENT_ROOT']:
* when launched via cron/console (cli) - empty
* when launched via a web server - contains the path to the root directory of the server (probably in your case it is /usr/bin/php /var/www/ user/data/www/domain/)
* more here
To get the current directory, you can use:
* __DIR__ - returns the path to the current file (script)
* getcwd() - returns the current working directory
* more about the difference between the methods here
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question