Search code examples
phpcentosfatal-errorrequire-once

require_once doesn't work in command line


php /home/test9/public_html/degerlendir/test-4567.php "var1=18&var2=22"

I need to run one page at background with cron job. I tested my code with command at above. But I get this error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/extensions/no-debug-non-zts-20100525/imagick.so' - /usr/lib64/extensions/no-debug-non-zts-20100525/imagick.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  require_once(../config.php): failed to open stream: No such file or directory in /home/test9/public_html/degerlendir/test-4567.php on line 2
PHP Fatal error:  require_once(): Failed opening required '../config.php' (include_path='.:/usr/lib64/php') in /home/test9/public_html/degerlendir/test-4567.php on line 2

The problem is page doesn't include config.php in the parent directory. The page working in browser normally. I tried to use different require_once variations like require_once ($_SERVER['DOCUMENT_ROOT']."/config.php"). I could not get it to work.


Solution

  • Cron jobs always take full path of the included file from your root.

    /home/test/.../your-file