Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Running the Laravel Scheduler and Queue with Docker
Apr 25, 2018 @ 14:26:26

On the Laravel News site today there's a tutorial posted showing you how to combine Docker and Laravel's Scheduler/Queue and make them still run as they would on a virtual server.

In Laravel, one of the tricky changes when switching from a virtual server to Docker is figuring out how to run a scheduler and a queue worker. I see this question come up quite a bit when PHP developers are trying to figure out how to use Laravel with Docker.

Should you run them on the host server? Should you run via cron in a Docker container?

There are a couple of ways I recommend running the scheduler command and Laravel queues in Docker, and we’re going to cover the basics of running both with a complete (albeit simple) Docker setup you can use to experiment.

Their approach uses a single multi-purpose Docker image rather than splitting the functionality up and making it more complex (Laravel subscribes to the monolithic approach anyway). The post then gets into the setup of this environment using Docker and docker-compose to configure several services: application (app), a Redis container and a MySQL container. The contents of the docker-compose and Dockerfile configurations are included as well as the VirtualHost configuration for the main site. Next it shows the use of the CMD directive to run a bash script when the build is brought up. This is what kicks off the scheduler/queue handling. The post finishes up with a few other changes needed to the Docker configuration and the creation of the "scheduler" service.

tagged: laravel scheduler queue docker tutorial service execute bash

Link: https://laravel-news.com/laravel-scheduler-queue-docker

SitePoint PHP Blog:
Managing Cronjobs with Laravel
Oct 27, 2015 @ 16:18:06

The SitePoint PHP blog has a tutorial posted showing you how to use the Laravel "scheduler" to handle cron jobs and the execution of custom commands.

There are times when your application needs to run administrative tasks periodically on the server. Whether you want to send out emails to your users or clean up the database tables at the end of the day, you will need a task scheduling mechanism to take care of the tasks, when it’s time. Cron is a task scheduler in unix-like systems, which runs shell commands at certain intervals.

They start with some of the basics of cron and how is configuration is defined. Since the Laravel scheduler makes use of the same format, they want to be sure everyone is on the same page. Next they show you how to create a custom command in Laravel, a simple script designed to be run on the command line. The tutorial shows how to execute the simple command and how to add it to your application's "commands" list in the configuration. Finally they get to scheduling the commands, defining a schedule method and using the Laravel helper methods to set the execution time to something like "daily", "hourly" or, if you need something a bit more custom, a full cron-formatted string. The post ends with the addition of the Laravel scheduler execution to the system cron, set to run every minute.

tagged: manage cronjob laravel scheduler custom tutorial command

Link: http://www.sitepoint.com/managing-cronjobs-with-laravel/


Trending Topics: