Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMasterBlog > Tips and Tricks

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Multiple Launches With One Cron Schedule

When you have several scripts that need to run at a specific frequency — a daily run of a script to compile stats from a log file is one example — setting up one cron instead of many may save time and frustration.

What you do is install the script below. In a separate file, list the URLs of the scripts that shall be run. Set up cron to run the script every day (or other schedule). When the script below runs, it does an HTTP request to each URL in your list, one URL at a time.

Unlike cron, this system lets you run scripts at any public URL at any domain, whatever PHP or other scripts that a browser or bot can access. Cron requires scripts to be available on the same server where cron is set up.

Most hosting companies provide a dashboard method for you to set up cron for your script. If your hosting company does not, articles Cron and Using Cron have information you may be able to use (warning, highly technical).

Here is the source code. One customization is required, talked about further below.

<?php
/*
Run All URLs
Version 1.0
March 17, 2024
Will Bontrager Software LLC
https://www.willmaster.com/
*/

// Specify the location of the file with the URLs to run.
$FileWithURLs = 'subdirectory/urls2run.txt';
// End of customizations.

$listOfURLs = array();
if( file_exists($FileWithURLs) ) { $listOfURLs = file($FileWithURLs); }
else { echo "File $FileWithURLs not found."; }
foreach( $listOfURLs as $url)
{
   $url=trim($url);
   if( preg_match('!^https?://!i',$url) )
      { file_get_contents($url); }
}
echo 'OK';
?>

Customization —

The above script will look for a text file (see next paragraph) that contains URLs to run. The text file can be anywhere on the server that could contain web pages.

When you have decided where to put the text file and what to name it, then replace subdirectory/urls2run.txt with the file's location. The file is not required to have a .txt file name extension; it can have any extension you wish to give it or even no extension at all. In other words, it needs to be a text file but you can give it any file name you wish to give it.

Upload the above source code as script runURLs.php or other *.php file name. Make a note of its URL.

Put the URLs of scripts you want to run into the text file specified in runURLs.php (see further above). URLs in the text file should be one URL per line. Script runURLs.php will ignore any lines that do not begin with http:// or https://.

Note: Do not specify the URL of runURLs.php in the text file containing URLs to run. You would end up with an infinite loop.

Set up a cron schedule for runURLs.php. Whenever runURLs.php runs, it will run the URLs in your text file as HTTP requests.

This system can put any URL on the internet on a scheduled run. URLs can be added and removed by updating the text file.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this blog post helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method


All information in WillMaster Blog articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

Recent Articles in the Library

Keeping Image Location Secret

The URL of an image embedded in a web page may be kept secret.

Easier Reading of JSON Data

For easier reading of JSON data, convert the JSON into an array.

Fixed Position Image

Position an image within a browser window that won't move even with page scroll.

Visually Centering Images

Sometimes an image that is technically centered doesn't look quite centered when viewed.

Cookie Directory Protection

Protecting subdirectories with a cookie can be an especially good method when access needs to be allowed from various internet connections.

Check SSL Certificate

An easy-to-use SSL checker to see when your secure certificate expires.

Strong Form Protection From Bots

A web page form that is invisible to spam bots.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List
software index page

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC