Software, your way.
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

Extracting Dates From the Unix Timestamp

The UNIX timestamp can be used to determine the represented time for any time zone on Earth.

Submit Form Data Without Bothering User

To silently and effectively submit a form on a web page, Ajax with FormData() can be used.

CSS Dots

CSS dots can be used for interactions between web page and website user.

Email Testing

One thing to test when email doesn't get sent or doesn't arrive is whether the server actuall sends email.

Tap to Select

Find out how to make a link or button to select the content in a div or other HTML element.

Capitalizing the First Letter of Words

Here, find both PHP code and JavaScript code to capitalize the first letter of a word.

Fixed-position Table Header

During a vertical scroll, the table header scrolls out of view -- unless the header is fixed in position.

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

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