Jump to content


Photo

Running Php File From Cron Job


  • Please log in to reply
7 replies to this topic

#1 sylvest

sylvest

    Family Friend

  • Members
  • PipPip
  • 96 posts

Posted 10 April 2017 - 05:34 AM

 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 by TCH-Bala, 10 April 2017 - 07:47 PM.
Please do not add sensitive information like domain and home directory paths on a public forum


#2 sylvest

sylvest

    Family Friend

  • Members
  • PipPip
  • 96 posts

Posted 10 April 2017 - 06:49 AM

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, 10 April 2017 - 07:46 PM.
Please do not add sensitive information like domain and home directory paths on a public forum


#3 TCH-Bala

TCH-Bala

    Technical Support Manager

  • Staff
  • PipPipPipPip
  • 1,754 posts

Posted 10 April 2017 - 09:02 PM

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.


Balakrishnan
Manager - Technical Support
TotalChoice Hosting, Inc.
http://www.totalchoicehosting.com

TCH Help Desk .. || .. TCH Blog

Posted Image

#4 sylvest

sylvest

    Family Friend

  • Members
  • PipPip
  • 96 posts

Posted 11 April 2017 - 05:00 AM

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



#5 TCH-Bala

TCH-Bala

    Technical Support Manager

  • Staff
  • PipPipPipPip
  • 1,754 posts

Posted 16 April 2017 - 06:53 PM

You can view your crons by logging into cpanel.

https://documentatio...y/ALD/Cron Jobs


Balakrishnan
Manager - Technical Support
TotalChoice Hosting, Inc.
http://www.totalchoicehosting.com

TCH Help Desk .. || .. TCH Blog

Posted Image

#6 sylvest

sylvest

    Family Friend

  • Members
  • PipPip
  • 96 posts

Posted 17 April 2017 - 11:16 AM

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



#7 TCH-Marshal

TCH-Marshal

    New To The Neighborhood

  • Staff
  • Pip
  • 17 posts

Posted 17 April 2017 - 04:04 PM

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.



#8 sylvest

sylvest

    Family Friend

  • Members
  • PipPip
  • 96 posts

Posted Today, 07:32 AM

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, Today, 07:33 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users