Welcome Guest, Not a member yet? Register   Sign In
Cron Library
#11

[eluser]sophistry[/eluser]
@drewbee...

that's what robots are for:
Code:
$this->load->library('user_agent');
if ($this->agent->is_robot())
echo 'would you please run this cron job for me, thanks, it will only take a minute.';
#12

[eluser]drewbee[/eluser]
[quote author="sophistry" date="1236888230"]@drewbee...

that's what robots are for:
Code:
$this->load->library('user_agent');
if ($this->agent->is_robot())
echo 'would you please run this cron job for me, thanks, it will only take a minute.';
[/quote]

Sure, but that is under the assumption that robots a) visit your page and b) visit your page frequently.
#13

[eluser]Phil_B[/eluser]
Drewbee could you post an example of what you have in mind? From what I've read exec() seems to be synchronous.
#14

[eluser]drewbee[/eluser]
exec forks into the unix background, giving you the ability to launch a process.

Scenario would be as follows:

User loads page>
- cron is fired off
- Available job needs to be launched
- exec(/path/to/script.php) : launches a seperate php process in the background
- cron completes (end of execution)
- forked process runs until complete (end of execution)

Code:
// taken from db query I assume
foreach ($cron_jobs->result AS $job)
{
    exec(escapeshellcmd('/usr/bin/php /cron.php --job=' . $job . ' > /dev/null/ &'));
}
I believe the & at the end of the command tells it to be asynchronous.

It has been a while since I have played with it, but anything can be done. Infact you can use exec to launch your own version of cron tab. Simply use sleep() to make sure it is not spinning the processor to 100% in a loop. But that is a whole other topic.

Also, I believe doing it this way you have to access the get parameters through argv()
#15

[eluser]sophistry[/eluser]
the PHP manual page for exec() has many comments about starting a process in PHP and then either letting it run on its own or tracking it by PID. also, if not on windows, look into pcntl on the PHP website too.
#16

[eluser]tdktank59[/eluser]
looks interesting however what sucks is when there is light traffic/no traffic then a cron could be late...
#17

[eluser]missionsix[/eluser]
[quote author="tdktank59" date="1236987319"]looks interesting however what sucks is when there is light traffic/no traffic then a cron could be late...[/quote]

So to to counter-act this, wouldn't it be smart to just setup a master 'cron' job controller, and then setup a regular cron job on the server to run this controller every 30 minutes or however often you need it to be run. Then, if there is light traffic, you can still execute the jobs within a reasonable amount of time.

This may seem counter-intuitive for cron jobs, but if you think about it, you can dynamically add more tasks and change their execution times on the fly without having to worry about messing with the server configuration or cpanel for example.



Nice library btw, looking forward to a sturdier version.
#18

[eluser]tdktank59[/eluser]
Well yeah that's nice there, and also the fact that it can all be controlled from lets say the admin/cron panel.

However im looking from reliability ive got some things that are on time sensitive things. And having cron jobs run ever minute could become a huge server load. (yes I have a few crons that run every minute)
#19

[eluser]missionsix[/eluser]
[quote author="tdktank59" date="1236989532"]Well yeah that's nice there, and also the fact that it can all be controlled from lets say the admin/cron panel.

However im looking from reliability ive got some things that are on time sensitive things. And having cron jobs run ever minute could become a huge server load. (yes I have a few crons that run every minute)[/quote]

If you are running crons every minute you would probably want to invest in another server that handles the cron jobs and have the two servers read of a separate database server. This is more of a scaling issue though.

Are you running some sort of web-crawler? Thats like the only thing i can think of that would need to be executed every minute.
#20

[eluser]tdktank59[/eluser]
Well at the moment Im not even running them... But I will have a Text Based RPG game that has to update stats every minute. To control "jail/hospital" time. as well as a few other things




Theme © iAndrew 2016 - Forum software by © MyBB