Hi there everyone,

I really need some help.

I have a load of PHP pages that generate XML feeds that need to run hourly for my site to function. Problem is I have run out of cron jobs with my hosting.

I wondered if there was a way of creating 1 PHP script that once the cron job runs it, it runs the other 10-15 pages automatically.

Any help would be greatly received as I am fast running out of ideas.

Thanks in advance.

Recommended Answers

All 10 Replies

Isn't that what loops are for ?

A cron job can be set to run any PHP script. You could run a script to run the whole job list unless you need a time gap between tasks. A PHP script cannot be trusted to handle time-delays of any significance.

Another alternative is to setup a task to run from your desktop at certain times. Each task could run a specific php page with handles a specific job.

On both Linux and Windows machines this can be done through an app called "Scheduled Tasks".

If you opt for a desktop option, be sure that your energy-saving settings don't turn off the harddrive or put your computer to sleep.

" have a load of PHP pages that generate XML feeds that need to run hourly for my site to function " = 1 cron job

<?php include('job1.php');
include('job2.php');
include('job3.php');
include('job4.php');
include('job5.php');
include('job6.php');
include('job7.php'); 
/* jeopardy music */ 
include('job9999.php'); ?>

I will give this a go. Thanks for the suggestion.

" have a load of PHP pages that generate XML feeds that need to run hourly for my site to function " = 1 cron job

<?php include('job1.php');
include('job2.php');
include('job3.php');
include('job4.php');
include('job5.php');
include('job6.php');
include('job7.php'); 
/* jeopardy music */ 
include('job9999.php'); ?>

Whether the multiple includes solution works or not is going to depend on how long the scripts take to run and the server timeout settings. If you're on a shared server, you won't have much control over the timeout settings which may disrupt your scripts after sixty seconds or so. If your scripts are accessing data from other sites, then the time they take to run is likely to vary, depending on routing and server load of the other sites. This means that it may work sometimes and not others.

I have done it and it seems to work apart from this error.

Cannot redeclare stripchars()

Any ideas???

" have a load of PHP pages that generate XML feeds that need to run hourly for my site to function " = 1 cron job

<?php include('job1.php');
include('job2.php');
include('job3.php');
include('job4.php');
include('job5.php');
include('job6.php');
include('job7.php'); 
/* jeopardy music */ 
include('job9999.php'); ?>

Hi there, the multiple includes seem to work, but I get the error Cannot redeclare stripchars(). Any ideas as to how I can solve this?

Whether the multiple includes solution works or not is going to depend on how long the scripts take to run and the server timeout settings. If you're on a shared server, you won't have much control over the timeout settings which may disrupt your scripts after sixty seconds or so. If your scripts are accessing data from other sites, then the time they take to run is likely to vary, depending on routing and server load of the other sites. This means that it may work sometimes and not others.

rather than have one php file include all the others, you could just run the 1st one and have it (at the end) run the second, etc.:
header("Location: job2.php");

Alternative: remove the stripchars() declaration in all but the first file. The problem with this method, is that there could be other functions that will give the same error.

You can use function_exists to prevent double definitions:

if (function_exists("function name") {
    function xxx(...) {

    }
}

I would suggest the following:

<?php file_get_contents('http://cronsubdomain.yoursite.com/job1.php');
file_get_contents('http://cronsubdomain.yoursite.com/job2.php');
file_get_contents('http://cronsubdomain.yoursite.com/job3.php');
file_get_contents('http://cronsubdomain.yoursite.com/job4.php');
file_get_contents('http://cronsubdomain.yoursite.com/job5.php');
file_get_contents('http://cronsubdomain.yoursite.com/job6.php');
file_get_contents('http://cronsubdomain.yoursite.com/job7.php');
 ?>

Then you will have no problems with memory limits and function definitions as they are each a separate request.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.