IberoMedia
IberoMedia

Reputation: 2304

execute http (otherwise know cron job) whenver page is loaded (php)

I would like to know if, and how, I can call or execute what otherwise would be known as a cron job

If I were to enter this crontab through my host cron manager interface it would look like:

wget "http://somedomain.com/index.php?option=csome_option&view=some_view&key=some_key&format=some_format"

Is it possible to run this http call everytime a page is loaded (using PHP)?

I do not want to display the outcome of this call, but rather simply execute what this call would get going if I were to call directly through a browser, but (inevitably sounding redundant) without displaying simply executing behind the curtains on cue from page load.

Thank you,

Upvotes: 0

Views: 233

Answers (2)

Michael Fenwick
Michael Fenwick

Reputation: 2494

If you are on a shared server that doesn't allow fopen, another trick is to add something like this to the page

<div style="display:hidden">
    <img src="/myphpscript.php" />
</div>

This will cause the php script to be run. You may also do well to have myphpscript.php output image headers so that the browser doesn't complain.

Upvotes: 2

Phil
Phil

Reputation: 164796

Assuming you have the fopen HTTP wrapper enabled...

$fp = fopen(
    'http://somedomain.com/index.php?option=csome_option&view=some_view&key=some_key&format=some_format',
    'rb');
if ($fp !== false) {
    fclose($fp);
}

Upvotes: 1

Related Questions