Solution for running phpcli in crotab

Source: Internet
Author: User
You have written a script using the php script and need to run it regularly in crontab, but the following error occurs: The code is as follows:


/Var/www/html/bt/e/BtSys :. :/usr/share/pear:/usr/share/phpPHP Warning: require (.. /class/connect. php): failed to open stream: No such file or directory in/var/www/html/bt/e/BtSys/torrents-scrape.php on line 17
PHP Fatal error: require (): Failed opening required '.. /class/connect. php '(include_path ='/var/www/html/bt/e/BtSys :. :/usr/share/pear:/usr/share/php ') in/var/www/html/bt/e/BtSys/torrents-scrape.php on line 17


Try solution 1 add the following code

Code

The code is as follows:


// Setting include path
$ Cur_dir = getcwd ();
$ Cur_dir = $ basedir = dirname (_ FILE __);
$ Path = ini_get ('include _ path ');
Ini_set ("include_path", "$ cur_dir: $ path ");
$ Path = ini_get ('include _ path ');
// Echo $ path;
Require (../class/a. php)
Require (../class/B. php)
...............


Operation failed

Try solution 2 Add the following code

The code is as follows:


$ Cur_dir = dirname (_ FILE __);
Chdir ($ cur_dir );
Require (../class/a. php)
Require (../class/B. php)


Running successful
Summary: If you run the php script in crontab in the relative directory of require, you must enter the directory where the script is located.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.