0

How to configuration Cron Job in cPanel for .PHP script.

I want to run it every day once a day.

Where i need to store this .php file ?

How can i check whether its working or not ?

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
Pratik Soni
  • 169
  • 2
  • 13
  • You could write the output to a log file use `>>` to append it. What do you have so far? – chris85 Jun 16 '15 at 16:08
  • I don't have more knowledge in cronjob. Can you share me any sample command ? – Pratik Soni Jun 16 '15 at 16:10
  • There are many docs, tutorials, and threads already on this topic. Please look at them; if you have specific issues please update/ re-ask. https://en.wikipedia.org/wiki/Cron#Examples and/or http://stackoverflow.com/questions/7332804/run-a-php-file-in-a-cron-job-using-cpanel – chris85 Jun 16 '15 at 16:11

3 Answers3

1

You can do it through command but since you using cPanel, use the interface:

enter image description here

Then fill out Add New Cron Job

enter image description here

For example, a cron for a php script that runs everyday at midnight sharp would look like this

Minute  Hour    Day   Month    Weekday  

0        0        *     *         *     php /path/to/script.php
meda
  • 45,103
  • 14
  • 92
  • 122
  • after set cornjob i got an error in email "Status: 404 Not Found X-Powered-By: PHP/5.4.38 Content-type: text/html No input file specified my script path /home/server/etc/extra/test.php?code=1 – Pratik Soni Jun 16 '15 at 16:58
  • 404 means not found your url is not correct please double check and try again – meda Jun 16 '15 at 16:59
0
  1. Click on the "Cron Jobs" icon inside cPanel, under Advanced.
  2. Make sure the current email address is valid. If not, enter a new email and click the "Update Email" button.
  3. Select the Common Setting you want. This will automatically change the other time settings.
  4. Alternatively, you may adjust the individual time settings. Minute, Hour, Day, Month and Weekday can be modified to achieve your goal.
  5. In the input box to the right of "Command", type the name of the file type, then add a space and provide the path to the file which you would like the command to run.

Click the "Add New Cron Job" button.

Link :

Here Link

JH_
  • 406
  • 1
  • 4
  • 15
Ramki
  • 519
  • 2
  • 9
0

You may put the file.php file in the "public_html" folder in your server. You have the option of cron job in the cpanel "Advanced" section. Once you're there you have the option to add a new cron job and "common setting" called "Once a day", which will satisfy your need. In the "command" field paste this: wget --spider http://yoursite.com/file.php and then save.

Of course this is not the best practice, but I hope it will do the job for you.

b14r
  • 332
  • 5
  • 18
  • after making changes i got response HTTP request sent, awaiting response 200 ok, Lengh: unspecified [text/html], remote file exists ad could contain further links, but recursion is disabled -- not retrieving – Pratik Soni Jun 16 '15 at 17:09
  • Did you try to access the file via http in your browser before creating the command? If it runs in your browser it will run in the wget for sure. Check if you specified the right url. – b14r Jun 16 '15 at 17:17
  • Script are working very fine, but i got email HTTP request sent, awaiting response... 200 OK Length: unspecified [text/html] Remote file exists and could contain further links, but recursion is disabled -- not retrieving. – Pratik Soni Jun 16 '15 at 17:22
  • My script have auto click option. But its not working properly. – Pratik Soni Jun 16 '15 at 17:58