Discussion:
Run a cron job in cakephp
abhimanyu bv
2011-11-04 02:19:15 UTC
Permalink
I would like to write a cron job that has to run a PHP script at 6am,
11am,2pm,4pm on each day.

Can you please help me with this? I wrote a shell task in shells and I
want to run that task at the timings i said in the earlier statement.

Thanks.
--
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Thiago Belem
2011-11-04 02:21:34 UTC
Permalink
Running a cronjob is something you do on your operating system, give a
look: http://en.wikipedia.org/wiki/Cron

Use this to call your shell task and you're done. :)
--
***Thiago Belem*
Desenvolvedor
Rio de Janeiro - RJ - Brasil

+55 (21) 8865.9250
thiagobelem.net
contato-rTTjcIT+***@public.gmane.org

*Skype / gTalk **»* thiago.belem.web
*LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt*
Assando Sites*, curso de CakePHP *»* assando-sites.com.br
Post by abhimanyu bv
I would like to write a cron job that has to run a PHP script at 6am,
11am,2pm,4pm on each day.
Can you please help me with this? I wrote a shell task in shells and I
want to run that task at the timings i said in the earlier statement.
Thanks.
--
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
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
euromark
2011-11-04 02:41:40 UTC
Permalink
you can use crontab to do that
http://book.cakephp.org/view/1110/Running-Shells-as-cronjobs

and here is explained how you can set the time accordingly:
http://neeocis.wordpress.com/2008/07/08/crontab-every-five-minutes/
Post by Thiago Belem
Running a cronjob is something you do on your operating system, give a
look:http://en.wikipedia.org/wiki/Cron
Use this to call your shell task and you're done. :)
--
***Thiago Belem*
Desenvolvedor
Rio de Janeiro - RJ - Brasil
+55 (21) 8865.9250
thiagobelem.net
*Skype / gTalk **»* thiago.belem.web
*LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt*
Assando Sites*, curso de CakePHP *»* assando-sites.com.br
Post by abhimanyu bv
I would like to write a cron job that has to run a PHP script at 6am,
11am,2pm,4pm on each day.
Can you please help me with this? I wrote a shell task in shells and I
want to run that task at the timings i said in the earlier statement.
Thanks.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
others with their CakePHP related questions.
To unsubscribe from this group, send email to
athttp://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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
abhimanyu bv
2011-11-04 04:29:46 UTC
Permalink
@euromark,
can you help me using crontab you posted in that link.
--
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Ryan Schmidt
2011-11-04 04:43:08 UTC
Permalink
Post by abhimanyu bv
@euromark,
can you help me using crontab you posted in that link.
This isn't a CakePHP question. You should be able to find many tutorials online about how to use cron.
--
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
zuha
2011-11-04 05:17:43 UTC
Permalink
While we're on the topic though... 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?
--
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Greg Skerman
2011-11-04 06:47:05 UTC
Permalink
I was reading recently about a deferred execution plugin....which kind of
did that I thought (i've not actually used it..)

https://github.com/MSeven/cakephp_queue/wiki

Queues a job, which gets picked up periodically by a worker and doesn't
hold up the page load.

Might be worth a look.
Post by zuha
While we're on the topic though... 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?
--
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
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
zuha
2011-11-04 14:23:53 UTC
Permalink
Oh that looks promising, if anything it should at least get us started.
Thank you for that : https://github.com/MSeven/cakephp_queue/wiki
--
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Ryan Schmidt
2011-11-04 06:50:03 UTC
Permalink
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
f***@public.gmane.org
2011-11-04 07:12:20 UTC
Permalink
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
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+unsubscribe-/***@public.gmane.org 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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Eric Blanpied
2011-11-04 08:16:58 UTC
Permalink
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
Post by f***@public.gmane.org
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
Post by Ryan Schmidt
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
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
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Werner Petry Moraes
2011-11-04 10:29:20 UTC
Permalink
Hi,

that cake method you call from within the worker, is it written as a shell?
Or how do you do it?
I'm not familiar with gearman, but I think I'm gonna need it soon.

thanks

atenciosamente,
Werner Petry Moraes
Post by Eric Blanpied
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
Post by f***@public.gmane.org
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
Post by Ryan Schmidt
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
Post by f***@public.gmane.org
Post by Ryan Schmidt
negatively effecting performance in a serious way. (I was thinking
curl,
Post by f***@public.gmane.org
Post by Ryan Schmidt
and ajax, but they didn't really seem to fit the bill) Any experts
out
Post by f***@public.gmane.org
Post by Ryan Schmidt
there know how to start a cron task outside of the page load, but
triggered
Post by f***@public.gmane.org
Post by Ryan Schmidt
by a page load?
cron is a program that schedules things to run at particular times of
the
Post by f***@public.gmane.org
Post by Ryan Schmidt
day. "start a cron task ... triggered by a page load" therefore doesn't
make
Post by f***@public.gmane.org
Post by Ryan Schmidt
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
Post by f***@public.gmane.org
Post by Ryan Schmidt
others with their CakePHP related questions.
To unsubscribe from this group, send email to
group
Post by f***@public.gmane.org
Post by Ryan Schmidt
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
group at
Post by f***@public.gmane.org
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
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Eric Blanpied
2011-11-04 13:36:20 UTC
Permalink
My workers are just PHP. I've got one doing curl stuff to transfer big
files, and another to drive ffmpeg for slow encodes. You can write
your Gearman clients in pretty much anything, though. They've got a
bunch of client libraries. The PHP one is pretty comprehensive, and
I've experimented with python workers, too. You can also post status
updates back from the worker if you want to do an ajax progress bar or
something.

There's a fair amount of stuff out there about gearman, but I found
this especially useful: http://tinyurl.com/y8vyc8f

I suppose we've left cake territory here, tho...

-e
Post by Werner Petry Moraes
Hi,
that cake method you call from within the worker, is it written as a shell?
Or how do you do it?
I'm not familiar with gearman, but I think I'm gonna need it soon.
thanks
atenciosamente,
Werner Petry Moraes
Post by Eric Blanpied
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
Post by f***@public.gmane.org
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
Post by Ryan Schmidt
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
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
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
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
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
zuha
2011-11-04 14:27:10 UTC
Permalink
Cron is not only for particular times, its also for recurring events. It
certainly does make sense if you simply set your task to check what time it
is before executing. Then you just "try" to run it every minute (or every
page load), and it will fire only at the appropriate time. This makes a
lot of sense for something like triggered notifications which don't happen
until X days after X event, and aren't at any particular time, but instead
are relative time.
--
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+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Loading...