Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2004, 07:19 AM
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I execute a code every X period of time?

I would like to know if there is Timer function available in PHP in order to execute part of my code every X time. If not how can i do it?

Do you have any sample code?
 
Old June 7th, 2004, 10:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

All servers have timers that will allow the to rerun pieces of code against a schedule. On Wiundows, this is known as a Scheduled Task, and on Unix, it's a cron job.

This is if you really just want the code to run at a set interval on the server - without any user intervention. (I say this, because sometime people ask this question on groups and lists, when all they really mean is that they want a page to refresh itself evey so often in a user's browser.)

Does that help at all?
 
Old June 8th, 2004, 09:15 AM
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is what i mean... a page that is being refreshed by itself without any condition. The problem is that i dont know how to implement this and The books I have don't refer something similar to this! Please Help!

 
Old June 8th, 2004, 10:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, in that case, you probably haven't found it in a PHP book because it's actually a HTML problem :).

Since page requests have to be made by the client, and cannot result from any action by the server (i.e. the web isn't a "push" technology", as they are still sometimes called), you have to instruct the browser to re-request the page every so often.

Put something like this in your page header:

<meta http-equiv="refresh" content="30;URL=your_page.php" />

That'll cause the browser to make a new request for the page, every 30 seconds (hence the number "30" in the content atribute). This will continue every 30 seconds for as long as the page remains open in the browser window. Be careful about this, though, since it can be very annoying to users on slow connections, who may never get a complete copy of the page before their browser makes a new request for it, and thus end up constantly looking at a part-completed page.

Take it easy
Dan





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Time out before actual timeout period zaheerabbas.sk ASP.NET 1.0 and 1.1 Basics 1 April 4th, 2007 04:45 AM
Can't execute code from a freed script pRogNewBie Classic ASP Components 0 October 23rd, 2006 10:46 PM
Execute Code Once Only brettk_1 Classic ASP Professional 5 May 29th, 2006 09:31 AM
can't execute code from a freed script violetcrystal Javascript 4 April 21st, 2006 05:04 AM
Calculate time period dtaya Access 1 July 26th, 2003 07:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.