Jump to content

Recommended Posts

[1]

In Javascript,

there is a function setTimeout() to call a function with a time interval..

 

In PHP, is there any similar in-built function ?

If there is a different solution, kindly provide me the code in php..

 

[2]

Using sleep():

 

I tried to create a page with sleep().

 

<?

echo "hello";

sleep(5)

echo "world";

?>

 

I did not get a "hello and after 5 seconds world". Instead it took 5 seconds to load and displayed entire content at once.

 

Can any provide me solution to these two problems?

Link to comment
https://forums.phpfreaks.com/topic/172237-create-a-clock-in-php/
Share on other sites

There is no settimeout in php, you could use the output buffer to display 'hello' before the sleep() cycle is finished, but it's buggy and is not a good solution.

 

I had another example for another thread on this topic.. but try this code.. place it at the top of your page, ob_start() has to atleast.

<?php
if (ob_get_level() == 0) ob_start();

echo "Hello";
echo str_pad('',4096)."\n";        
        ob_flush();
        flush();
        sleep(5);

echo "world";
echo str_pad('',4096)."\n";        
        ob_flush();
        flush();
        sleep(0);

ob_end_flush();
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.