Jump to content

Running Php File From Cron Job


Recommended Posts

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
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 by TCH-Bala
Please do not add sensitive information like domain and home directory paths on a public forum
Link to comment
Share on other sites

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 by TCH-Bala
Please do not add sensitive information like domain and home directory paths on a public forum
Link to comment
Share on other sites

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.

Link to comment
Share on other sites



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.



Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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: execute
Zend 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 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-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:

  1. 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.
  2. Why is the session cookie that it is sending set to Expires: Thu, 19 Nov 1981?
  3. 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 by sylvest
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...