Jump to content

Cron Jobs?


poirot

Recommended Posts

OK, I've posted this a year ago; but since I got no answer I'll post it again.

How do you make PHP scripts act like cron jobs?
For example, you need to "lock" a page on a certain date. (after that it will no longer be visible).

You could make it check for expiration every time the script is loaded...
BUT this wouldn't be a great idea IF the script is accessed often.

And what I can't do with something like this: email a "daily digest" of some message board to myself or whoever is subscribed to it.

Is there any way, besides cron jobs, to make scripts execute themselves in a programmed time?

Thanks in advance [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]
Link to comment
Share on other sites

you can also call the php from your cron job "php /path/to/your/php/script.php"

and you need the path to the php compiler (I think that what it's called) in the tob of you php file "#!/usr/local/bin/php -q"
Link to comment
Share on other sites

Thanks for the suggestion guys ...
If I use my computer though it may not be reliable since it's not on 24/7.

I guess the only way is to find a server with Cron Jobs and remotely execute them...
Link to comment
Share on other sites

[!--quoteo(post=379984:date=Jun 4 2006, 11:32 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 4 2006, 11:32 AM) [snapback]379984[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you know..i was gonna say before, if a host doesn't offer the ability to run cron jobs... why bother even going with them?
[/quote]
Lack of Funds [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]
Link to comment
Share on other sites

I found a few websites that offers alternative service to cron a while back, but I never tried them. you can search Cron Service on google to find more details. Here are two quick links

[a href=\"http://www.fastcron.com/\" target=\"_blank\"]http://www.fastcron.com/[/a]

[a href=\"http://www.webbasedcron.com/\" target=\"_blank\"]http://www.webbasedcron.com/[/a]
Link to comment
Share on other sites

Why not just add to the top of that page a simple line of code that says something like this...
[code]
$now = time();
if ($now > $whenever) exit;
[/code]

for the whenever you can just use the time function add feed it some numbers:
[a href=\"http://us3.php.net/time\" target=\"_blank\"]http://us3.php.net/time[/a]
Link to comment
Share on other sites

[!--quoteo(post=380399:date=Jun 5 2006, 03:48 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 5 2006, 03:48 PM) [snapback]380399[/snapback][/div][div class=\'quotemain\'][!--quotec--]
yeah that's fine and dandy except that it requires the script to be accessed in order to do that. And if you were gonna do that, then there would be no point. Just access it whenever you need to. the point of cron jobs is that it's automated.
[/quote]
Exactly. And also, if you do this check everytime it access something that is scheduled to be executed every 24 hours, it's not good.
Link to comment
Share on other sites

  • 2 weeks later...
i have the same problem. i have a few scripts which generate a image. and out that image to a file.

the file only gets updated when the script runs. My free host supports cron jobs.

but im lost as to how to get it working. all tutorials i read say u need root acces or lynx which my host dose not have.

any ideas on how to execute a PHP script form cron
Link to comment
Share on other sites

[!--quoteo(post=385929:date=Jun 20 2006, 11:10 AM:name=maxim)--][div class=\'quotetop\']QUOTE(maxim @ Jun 20 2006, 11:10 AM) [snapback]385929[/snapback][/div][div class=\'quotemain\'][!--quotec--]
i have the same problem. i have a few scripts which generate a image. and out that image to a file.

the file only gets updated when the script runs. My free host supports cron jobs.

but im lost as to how to get it working. all tutorials i read say u need root acces or lynx which my host dose not have.

any ideas on how to execute a PHP script form cron
[/quote]
If you don't have access to it through a GUI such as cPanel, you'd need to have SSH access to write the contab manually.
Link to comment
Share on other sites

[!--quoteo(post=385968:date=Jun 20 2006, 09:34 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 20 2006, 09:34 PM) [snapback]385968[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If you don't have access to it through a GUI such as cPanel, you'd need to have SSH access to write the contab manually.
[/quote]

yeah i do have the access to the cPanel GIU and as it turns out it works ! here the entery into cron tab i made

[code]00 * * * *  php /home/MyUserName/public_html/script.php[/code]

i belive it updates once every hour/day/week/year.

how ever i test all my scripts localy before i upload them

so when i put that crontab entry into my own local machines crontab it didnt work !

see how i have the word "php" before the path to my script. what dose crontab do when it sees that ?
Link to comment
Share on other sites

A great looking alternative to cronjobs would be [a href=\"http://www.dwalker.co.uk/phpjobscheduler/\" target=\"_blank\"]http://www.dwalker.co.uk/phpjobscheduler/[/a] I found this free script by accident earlier today when I was looking for an script to automatically backup my databases to server. I havn't tested it but it looks like it could do what you are asking ;)
Link to comment
Share on other sites

[!--quoteo(post=386124:date=Jun 20 2006, 08:18 PM:name=maxim)--][div class=\'quotetop\']QUOTE(maxim @ Jun 20 2006, 08:18 PM) [snapback]386124[/snapback][/div][div class=\'quotemain\'][!--quotec--]
see how i have the word "php" before the path to my script. what dose crontab do when it sees that ?
[/quote]
The part where you have "php" is pointing to your install of php on the system, it looks like your host is set up to accept "php" as the path to php. If this is not working on your local machine, try pointing it to "usr/local/bin/php", I think thats the default install location (providing you're running a *NIX OS on your local machine. I am assuming you do as you said you have cron.)
[!--quoteo(post=386140:date=Jun 20 2006, 09:29 PM:name=rsj1)--][div class=\'quotetop\']QUOTE(rsj1 @ Jun 20 2006, 09:29 PM) [snapback]386140[/snapback][/div][div class=\'quotemain\'][!--quotec--]
A great looking alternative to cronjobs would be [a href=\"http://www.dwalker.co.uk/phpjobscheduler/\" target=\"_blank\"]http://www.dwalker.co.uk/phpjobscheduler/[/a] I found this free script by accident earlier today when I was looking for an script to automatically backup my databases to server. I havn't tested it but it looks like it could do what you are asking ;)
[/quote]
That still requires user interaction to trigger the script, automation without a scheduling application like cron or scheduler is impossible.
Link to comment
Share on other sites

[!--quoteo(post=386148:date=Jun 20 2006, 10:32 PM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Jun 20 2006, 10:32 PM) [snapback]386148[/snapback][/div][div class=\'quotemain\'][!--quotec--]
That still requires user interaction to trigger the script, automation without a scheduling application like cron or scheduler is impossible.
[/quote]
Very true, but it looks like a great alternative to cron jobs if your host does not support them ;)
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.