douan7529 2017-02-08 09:38
浏览 60

Heroku上的Laravel:计划任务

I working currently on a simple Reminder Laravel app for Heroku. I've written my API and everything works well. Now I want to run a scheduled task on Heroku.

Basically I'm looking for something to execute the following command on a separate dyno:

php EmailScheduler.php

or

php artisan schedule:emails

This command should be a long running process where e.g. each minute the same task is being executed over and over.

In this task I want to query my database and get all reminders that are due and send them as an email so I have to be able to access the business logic of my application like eloquent models.

I know about the scheduler add-on or about certain "cron" solutions but I would like a PHP only solution so just a long running script or task that might sleep most of the time and wake up each minute or so.

In Ruby (Rails) for example I could require the environment, thereby have access to my business logic and then fire up a timer task using the concurrent-ruby library.

I already tried to require the

bootstrap/autoload.php
bootstrap/app.php

files but it seems like I have to do more than just this, like boot the application.

How can I solve this using the Laravel framework and possibly other third-party libraries ?

  • 写回答

1条回答 默认 最新

  • dsfdsf46465 2017-02-08 10:36
    关注

    Task Scheduling in laravel is done by making a cron job. By defining a cron job, one can schedule a task to be excuted at a defind period. You follow the official documentation of laravel for scheduling: https://laravel.com/docs/5.3/scheduling

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名