cron job in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vikasbatra
Forum Newbie
Posts: 2
Joined: Thu Sep 27, 2007 8:17 am

cron job in php

Post by vikasbatra »

Hi friends,

i want to set up a cron job in php with php code, i don't have access to admin panel(control panel) of site.
so that's why i want to set up a cron job using php code. i already have some code related to cron job but that is not working, can any body have this type of code that can set cron job then pls mail me or send me links......



my mail id: vikas_batra06@yahoo.co.in, vikasbatra2006@gmail.com
anchises
Forum Newbie
Posts: 3
Joined: Thu Sep 27, 2007 5:42 am

Post by anchises »

Best bet would be to find a host who allows you to set up cron jobs.

Don't think it's really possible to manipulate cron itself using php. Not without system calls, anyway.

Failing that, I'd set up a small bit of code which checks, each time somebody requests a page, what the system time is and whether it needs to carry out a cron.

This means that you'll need to :
  • a) store the last time that the cron job was run (either in a database or file) - let's call it var_last_time;
    b) work out the next time that the cron job needs to run (for instance, the stored time plus 24 hours) - let's call it var_next_time;
    c) work out whether the current time is after var_next_time. If it isn't, don't do anything; if it is...
    d) ... run the cron job, store var_next_time as var_last_time;
    and carry on.
This works okay for regularly visited sites, but it gets more complicated if a number of periods elapse between a) and b) - you have to work out how many, make sure the cron job runs the right number of times, etc.

It also rather adds to the overheads of the scripts.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Wow, I stopped development of my PHPCronEmulator because I thought there was no interest in it. :-P
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply