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

SitePoint PHP Blog:
A Comprehensive Guide to Using Cronjobs
Mar 31, 2016 @ 12:18:47

If you've ever wanted to learn about cron jobs, how to set them up and what kind of functionality they provide then the SitePoint PHP blog has the post for you. In this comprehensive guide to cron you learn about these topics and more.

There are times when there’s a need for running a group of tasks automatically at certain times in the future. These tasks are usually administrative, but could be anything – from making database backups to downloading emails when everyone is asleep. [...] This article is an in-depth walkthrough of this program, and a reboot of this ancient, but still surprisingly relevant post.

They start by going through some of the basic terminology and syntax, where the cron files live and what a typical file format looks like. Also included are instructions on:

  • how to edit the cron correctly (crontab)
  • the structure of each cron entry
  • how to have it run at the time you want
  • editing another user's crontab
  • cron permissions
  • redirecting output

They also talk about executing PHP in a cron job, how to prevent overlaps with a "lock" file . There's also a mention of Anacron as a replacement for cron and a few helpful hints to help you debug when things go wrong.

tagged: cron cronjob tutorial comprehensive guide configuration execution

Link: http://www.sitepoint.com/a-comprehensive-crash-course-into-cronjobs/

SitePoint PHP Blog:
Managing Cronjobs with Laravel
Oct 27, 2015 @ 11: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/

Managing Cron Jobs with PHP
Apr 08, 2011 @ 12:39:30

New on NetTuts.com there's a tutorial about using cron with PHP and how to manage the jobs your server currently runs.

The cronTab, or “Cron Table”, is a Linux system process / daemon which facilitates the scheduling of repetitive tasks thereby easing up our day to day routine. In this tutorial, we’ll create a dynamic PHP class that, using a secure connection, provides us with a means to manipulate the cronTab!

They explain the cron format (time and script to run) and how to set up a crontab management class that uses the ssh extension for PHP to communicate with the remote server. Their class includes methods for setting up jobs, writing them out to the cron file, removing existing jobs and dropping the entire cron file at once.

tagged: cronjob manage ssh tutorial