sylvest Posted April 10, 2017 Posted April 10, 2017 (edited) Is it possible to run a PHP program from a cron job? I am trying to do this, and have set up a cron job to run /home/myaccount/include/do_email.php once per day at 3am. It attempts to do it, but fails as follows: [06-Apr-2017 20:49:33 America/Detroit] PHP Warning: require_once(basic_init.php): failed to open stream: No such file or directory in /home/xxxx/public_html/swchoir/index.php on line 2 [06-Apr-2017 20:49:33 America/Detroit] PHP Fatal error: require_once(): Failed opening required 'basic_init.php' (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home/xxxx/public_html/swchoir/index.php on line 2 My first question is, why is it trying to run index.php, which is my default page, but is not involved in do-email.php at all, as far as I can see. The second question is why is the include path set to '.:/opt/cpanel/ea-php56/root/usr/share/pear'? I have the following in my php.ini file: include_path = ".:/home/myaccount/include:/usr/lib/php:/usr/local/lib/php" Which works fine when running the PHP files as part of web pages, but it seems that this is not working in a cron job. I hope you can help me put my finger on why this is not working. Thank you - Rowan Edited April 11, 2017 by TCH-Bala Please do not add sensitive information like domain and home directory paths on a public forum Quote
sylvest Posted April 10, 2017 Author Posted April 10, 2017 (edited) It tried to run the job last night. I noticed the following from my log: [10-Apr-2017 02:07:32 UTC 0 +00:00 GMT] on L_TRACE REQUEST_URI = / at line 82 in file /home/xxx/include/basic_init.php[10-Apr-2017 02:07:32 UTC 0 +00:00 GMT] on L_TRACE SERVER_NAME = xxx.yyy.org at line 83 in file /home/sylvest/include/basic_init.php Where are these values coming from when the file is run in a cron job? The subdomain xxx.yyy.org does exist, from some work I did in the past, but I'm not using it currently. So how has it deduced that this is the Server? These values are returned correctly when I am running as a result of an HTTP request. Is there some way I can detect, in the script, that it is running in a Cron job, and in that case ignore these values? Thanks - Rowan Edited April 11, 2017 by TCH-Bala Please do not add sensitive information like domain and home directory paths on a public forum Quote
TCH-Bala Posted April 11, 2017 Posted April 11, 2017 I have edited the crontab entry which should resolve some of the issues that you are seeing. Checking the ini file, it looks like there are a lot of entries that actually are not needed. I would recommend that you delete off the ini file and create a new one using the cpanel - Multi PHP ini editor, and add only the needed parameters so that most of the unnecessary ones that could interfere with your script are removed. Once this is done, you will get a better idea of what the problem is and if there is something that needs to be checked server side, please open a ticket to our support department with all the details so that we can check it out. I have edited out the domain and user fields from your threads, as pasting them on an open forum is not recommended. Quote
sylvest Posted April 11, 2017 Author Posted April 11, 2017 Balakrishnan, Thanks for your help with this. Just out of interest, where is "the crontab entry"? Where can I see this, just so I understand what you have done? I will look at simplifying the php.ini file as you suggest, although I may need to ask which entries are necessary and which are not. Thanks again for your help. The excellent support that the TCH team provides is one of the main reasons I stick with you. Rowan Quote
TCH-Bala Posted April 16, 2017 Posted April 16, 2017 You can view your crons by logging into cpanel. https://documentation.cpanel.net/display/ALD/Cron+Jobs Quote
sylvest Posted April 17, 2017 Author Posted April 17, 2017 Thank you. I think you can close this ticket now. If I can't get the cron job to work properly after sorting out the INI file I will raise another one. Thanks - Rowan Quote
TCH-Marshal Posted April 17, 2017 Posted April 17, 2017 Hi Rowan, Glad to know that everything is working but note that you have actually posted on our forums about this issue and next time it will be better you use our helpdesk to open a ticket for more privacy. Our helpdesk url is https://support.totalchoicehosting.com. Alternatively you can send an email to support@totalchoicehosting.com to open an helpdesk ticket. Quote
sylvest Posted April 26, 2017 Author Posted April 26, 2017 (edited) Here's an error reported from last night's attempt to run my PHP file in a cron job: Failed loading /opt/cpanel/ea-php54/root/usr/lib64/php/modules/ioncube_loader_lin_5.4.so: /opt/cpanel/ea-php54/root/usr/lib64/php/modules/ioncube_loader_lin_5.4.so: undefined symbol: executeZend Guard Loader requires Zend Engine API version 220100525.The Zend Engine API version 220131226 which is installed, is newer.Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Guard Loader.Set-Cookie: PHPSESSID=p4nu293cl2kikl2tb7t7ooo4j6; path=/Expires: Thu, 19 Nov 1981 08:52:00 GMTCache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0Pragma: no-cacheContent-type: text/html; charset=UTF-8<br /><b>Fatal error</b>: Class 'PasswordHash' not found in <b>/home/myaccount/include/do_email.php</b> on line <b>153</b><br /> Questions arising: Why am I getting the undefined symbol: execute error? This seems to be something to do with loading PHP, before it has ever tried to access my script. Why is the session cookie that it is sending set to Expires: Thu, 19 Nov 1981? Why has it failed to find PasswordHash? This file runs correctly when called as part of my website, so I think the problems must be to do with diffferences between the environment when run as a web page and when run as a cron job. Thanks - Rowan Edited April 26, 2017 by sylvest Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.