Welcome Guest, Not a member yet? Register   Sign In
Fake cron?
#1

[eluser]brigham[/eluser]
Does anyone have something like a "pseudo cron" to execute periodic jobs (database optimizations, etc.) in CI?

I say "pseudo" since it would only be able to execute when a page gets served.

It seems like it would be a cool CI library...
#2

[eluser]coolfactor[/eluser]
Why not use a real cron job? I do that with 2 of my sites and it's been working flawlessly. You want the cron job to simulate an HTTP request, rather than run the PHP scripts directly, though. That helps to avoid permission errors.
#3

[eluser]marcoss[/eluser]
If you really need to do it on runtime, you should check WordPress implementation.
#4

[eluser]brigham[/eluser]
I would prefer not to use real cron for a few reasons:
1. I can't assume I have access to crontab
2. The site adjusts timing of the cron jobs according to site useage
3. I would rather keep all configuration info in one place
#5

[eluser]Derek Allard[/eluser]
I've not thought about this in too much detail, but I like the idea in principal, especially for applications that you distribute, as you can never be sure of the environment they'll get set up in.

In order to not delay the loading of the page you're using, I would think an ajax request to a cron controller, triggered onload would be best. Its true that this wouldn't get called for visitors with js disabled, but since we're checking it every page load anyhow, that shouldn't be a problem.

It would be easy enough to have a table called "cron_jobs" or something, with timestamps dictating if something should be run.
#6

[eluser]marcoss[/eluser]
Again, take a look at WordPress implementation, it works pretty well.

http://svn.automattic.com/wordpress/trunk/wp-cron.php
http://svn.automattic.com/wordpress/trun...s/cron.php
#7

[eluser]sophistry[/eluser]
Or if you have a public site you can use CI's user agent class to make the robots run cron jobs for you.

Code:
if ($this->agent->is_robot())
{
  //run pseudo cron job
}
#8

[eluser]esra[/eluser]
If you are attempting to design an application that runs on all web servers, using CRON is not a good choice if Windows support is desirable. PHP does not support multiple threads, but methods of simulating multithreaded operations have been developed.

There are a couple of classes on phpclasses.org that simulate multithreading (do a search on 'thread'). I have never used these myself, but the general approach seems useful for handling your needs. You could spin off a new thread to handle background processing operations and build an admin interface to handle scheuled events for those background operations, possibly based on CI's calendar library.
#9

[eluser]sophistry[/eluser]
@esra,

Just my 2ยข... but I wouldn't recommend the CI calendar class for anything where you might want to build a lot of functionality into it - you end up concatenating a lot of links and form fields and blech. It's good for drawing a monthly calendar with one link per day and that's about it. I'd stick to a simple "type your date here" kind of admin interface.
#10

[eluser]Rick Jolly[/eluser]
So many smart people on this forum. I love derek's ajax suggestion and sophistry's robots suggestion.




Theme © iAndrew 2016 - Forum software by © MyBB