PHP: running scheduled jobs (cron jobs)

前端 未结 13 1567
自闭症患者
自闭症患者 2020-11-22 14:36

I have a site on my webhotel I would like to run some scheduled tasks on. What methods of achieving this would you recommend?

What I’ve thought out so far is having

13条回答
  •  伪装坚强ぢ
    2020-11-22 14:55

    I'm answering this now because no-one seems to have mentioned this exact solution.

    On a site I'm currently working on, we've set up a cron job using cPanel, but instead of running the PHP Interpreter directly (because we're using CodeIgniter and our code is mapped to a controller function, this probably isn't a great idea) we're using wget.

    wget -q -O cron_job.log http://somehost/controller/method
    

    -q is so that wget won't generate any output (so you won't keep getting emails). -O cron_job.log will save the contents of whatever your controller generates to a log file (overwritten each time so it won't keep growing).

    I've found this to be the easiest way of getting 'proper' cron working.

提交回复
热议问题