I think the best way to do it is with a queue. After doing several
websites in which cron jobs were used for various not-so-cron things
(cron job to wake up periodically and check for needed tasks? why not
just spawn the tasks?), I came to the conclusion that a job queue was
a much smarter answer.

Accordingly, I've just woven Gearman (http://gearman.org/) into one of
our cake projects, with a very simple component wrapping the gearman
client. The workers are pure php, with no knowledge of the app or
database, reducing dependencies as well as possible. The client passes
the workers json-encoded parameters, and the workers call a cake
method when done, again with json-encoded return data, and cake makes
any database updates as appropriate. Now we can do all sorts of things
outside of the user's browser session, and in the future could move
these things off to a different server if we wished.

Of course, if your other tasks were very much cake-related, and you
wanted them to use the framework, I see no reason why you couldn't
write your workers within the framework.

There are other queue/messaging systems out there (beanstalk's got a
good following), but in my research I liked what gearman had to offer
best. There's also Persson's cakephp Queue plugin, but I wanted a
lighter system, with no cake dependencies on the worker side.

-e

On Fri, Nov 4, 2011 at 8:12 AM, flo.kl...@googlemail.com
<flo.kl...@googlemail.com> wrote:
> What about using javascript. It would only work while the user is on the
> site, but it would be able to call a function (also ajax if you want to
> trigger a php method) very x seconds.
>
> -flosky
>
>
>
> Ryan Schmidt <google-2...@ryandesign.com> schrieb:
>>
>> On Nov 4, 2011, at 00:17, zuha wrote:
>>
>> > is there anyway to run a process separate from the page load.  I would
>> > love to run a pseudo cronjob on each page load if it could be done without
>> > negatively effecting performance in a serious way.  (I was thinking curl,
>> > and ajax, but they didn't really seem to fit the bill)   Any experts out
>> > there know how to start a cron task outside of the page load, but triggered
>> > by a page load?
>>
>> cron is a program that schedules things to run at particular times of the
>> day. "start a cron task ... triggered by a page load" therefore doesn't make
>> sense.
>>
>> What kind of task do you want to start? The solution might be different
>> depending on the task.
>>
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to