CakePHP: Run shell job from controller -
CakePHP: Run shell job from controller -
is possible utilize dispatchshell controller?
my mission start shell job when user has signed up.
i'm using cakephp 2.0
if can't mitigate need dogmatic suggests then, read on.
so have (potentially) long-running job want perform , don't want user wait.
as php code user executing happens during request has been started apache, code executed stall request until completion (unless nail apache's request timeout).
if above isn't acceptable application need trigger php outwith apache request (ie. command line).
usability-wise, @ point create sense notify user processing info in background. message telling them can check later spinning progress bar polls application on ajax observe job completion.
the simplest approach have cronjob executes php script (ie. cakephp shell) on interval (at minimum, 1 time per minute). here can perform such tasks in background.
some issues arise background jobs however. how know when failed? how know when need retry? if doesn't finish within cron interval.. race-condition occur?
the proper, more complicated setup, utilize work/message queue system. allow handle above issues more gracefully, require run background daemon on server grab , handle incoming jobs.
the way works is, in code (when user registers) insert job queue. queue daemon picks job instantly (it doesn't run on interval it's waiting) , hands worker process (a cakephp shell example). it's instant , - if tell - knows if worked, knows if failed, can retry if want , doesn't accidentally handle same job twice.
there number of these available, such beanstalkd, dropr, gearman, rabbitmq, etc. there number of cakephp plugins (of varying age) can help:
cakephp-queue (mysql) cakephp-queue-plugin (mysql) cakeresque (redis) cakephp-gearman (gearman) and others.i have had experience using cakephp both beanstalkd (+ php pheanstalk library) , cakephp queue plugin (first 1 above). have credit beanstalkd (written in c) beingness lightweight, simple , fast. however, regards cakephp development, found plugin faster , running because:
the plugin comes php code need started. beanstalkd, need write more code (such php daemon polls queue looking jobs) the beanstalkd server infrastructure becomes more complex. had install multiple instances ofbeanstalkd
dev/test/prod, , install supervisord
after processes). developing/testing bit easier since it's self-contained cakephp + mysql solution. need type cake queue add together user signup
, cake queue runworker
. shell cakephp
Comments
Post a Comment