Jump to content

Run a PHP Script in Crontab


jester626

Recommended Posts

I am trying to run a PHP Script in a crontab. I have added: #!/usr/local/bin/php -q at the top of the php page/script.  I have also set up the crontab as follows:

 

00 40 * * * /var/www/the/rest/of/the/path/file.php

 

This should run the script everyday at 00:40. 

 

But to no avail. I am using PHP 5.1.6

 

Any help would be appreciated

 

Jester

Link to comment
Share on other sites

I had the same problem, theirs an easy way to fix this and get the cronjob running.  ;)

 

change this:

00 40 * * * /var/www/the/rest/of/the/path/file.php

 

to this:

00 40 * * * php /var/www/the/rest/of/the/path/file.php

 

Note: you must have a space after the php

 

Regards ACE

Link to comment
Share on other sites

I hate to impose on this thread with a question, but you guys are talking about what I am interested in creating too. I want to be able to create a cron; but I do not have a c-panel on my web host. I tried to open up a notepad file and ad some cron code to it and save it with a ".cron" extension, but this did not work. I do not know anything about crons except what I have been reading about for the past hour. How can I create a cron without c-panel and what extension should I save it as? Is there any thing special I need to set up with my web host to make crons work? Here is the code I put in the text file that I first spoke of.

 

15 * * * * /usr/local/bin/php -q /10-26-2007.php

 

 

I found this code and tried it, but it did not work - any suggestions or answers would be awesome.

Link to comment
Share on other sites

What did you use as the first line of your php file?

Did you use #!/usr/local/bin/php -q  ?

 

Thanks

 

you don't need anything in the file you are running in the cron, it runs fine without it.

 

I hate to impose on this thread with a question, but you guys are talking about what I am interested in creating too. I want to be able to create a cron; but I do not have a c-panel on my web host. I tried to open up a notepad file and ad some cron code to it and save it with a ".cron" extension, but this did not work. I do not know anything about crons except what I have been reading about for the past hour. How can I create a cron without c-panel and what extension should I save it as? Is there any thing special I need to set up with my web host to make crons work? Here is the code I put in the text file that I first spoke of.

 

15 * * * * /usr/local/bin/php -q /10-26-2007.php

 

 

I found this code and tried it, but it did not work - any suggestions or answers would be awesome.

 

I don't know if its possible to run cronjobs without cron in C-panel, I've never heard of it done any other way sorry  :-\

 

Regards ACE

Link to comment
Share on other sites

ok - if I cannot not run crons without C-Panel; is there any way to automate a php script? another member of this forum suggested ajax, but I thought that ajax had to always be executed by client side events. is there a way to automate a php script with ajax; without any interaction with ajax/php script (totally automated timed events - like cronjobs)?

Link to comment
Share on other sites

Do you have shell access to your webhost? Meaning can you access it through a terminal window (such as putty)?

 

If you can access your host via a terminal window then you can try and see if it will let you do a "cron -e"

 

This may or may not work depending how your hosting provider has configured the domains. I would suggest you contacting them and asking them if it is possible.

 

Hope this helps,

 

Jester

Link to comment
Share on other sites

Thank For The Help jester626 And MasterACE14

 

I am only able to access my files directly through my web host file manager (not really like a terminal window software; it's built right into a web page - not really much of a control panel - very basic stuff - may have to upgrade sometime to accomplish cronjobs).

Link to comment
Share on other sites

ok - if I cannot not run crons without C-Panel; is there any way to automate a php script? another member of this forum suggested ajax, but I thought that ajax had to always be executed by client side events. is there a way to automate a php script with ajax; without any interaction with ajax/php script (totally automated timed events - like cronjobs)?

 

their is a PHP function that was suggested to me a while back, called "sleep()" and "usleep()" , look them up at php.net , that could possibly work.

 

Regards ACE

Link to comment
Share on other sites

ok - if I cannot not run crons without C-Panel; is there any way to automate a php script? another member of this forum suggested ajax, but I thought that ajax had to always be executed by client side events. is there a way to automate a php script with ajax; without any interaction with ajax/php script (totally automated timed events - like cronjobs)?

 

Create the script on your host and call it from another computer using some kind of scheduler?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.