Hi DP Members, I have been working on a project and need to create a clock in php, so, does PHP have a function like setTimeout() or something?
Hi, I couldn't find out that function in PHP's manual. You are talking about a custom function ? @webshore88 : Please provide more details regarding what you are trying to do or what functionality that you are needed.
Keep in mind the sleep function performs WHILE a connection is live. Once content is delivered the general rule is to disconnect. By forcing the PHP script to sleep you may open yourself up for all kinds of unexpected problems. What exactly are you trying to do?
Agree with NetStar, what are you trying to do? sleep() basically completely halts execution for x amount of time, it doesn't perform like setTimeout() in JS whereas you can set a function to execute later and continue executing functions, etc...
In JavaScript setTimeout() calls a function at a set time. PHP doesn't have this feature. And even if you CAN imitate the function it will NOT behave the same. PHP can't change elements in your browsers DOM nor can it control ANYTHING with the browser aside from outputting data. If you want to call a specific function after a page has been loaded you need to use JavaScript...or more specifically some sort of AJAX/Jquery call to rest, create a subliminal new http request to fetch data from a PHP script.
It could be possible with some tricks. There is gearman and threading (for linux only) that I know of.
Hello Guys. When I started using Javascript I had read a few tutorials, but I discovered there were many things they had not covered. There is a lot of information on the web but it helps if you search for a particular feature. All your comment for php development are welcome. Thanks in advance.
No it's not. You stated you wanted to "create a clock in php". PHP is not a markup or presentation language. It's a programming language that merely receives/sends/prints data. The only thing you can do with PHP to create a clock is to print the time to the browser. If you want a LIVE clock that updates via the DOM (or I will say document) you will need to use a dynamic language that is read by the browser. That would be JavaScript. Using sleep is a terrible idea. Why? Because it's not going to work the way you want it to. sleep() would literally "pause" the entire program. Think of it this way: you're driving down the road to your girlfriends house. Every 15 seconds you must stop for a 30 second red light (sleep(30)). While you are stopped at the light you aren't doing ANYTHING. Then you start moving again but guess what? Your girlfriend will never see you because you are on the wrong road. Using PHP to create a clock would be using the wrong road. You will eventually find out for yourself...