Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time delay before print "hello world"!!! 1

Status
Not open for further replies.

brogan

Technical User
Oct 7, 2003
44
GB
I'm creating a PHP script that interacts with the customer, slightly like Pandora Bot and Eliza. I want a time delay before "hello world" is printed to make it appear as if the computer is thinking/typing.

Any ideas would be great!

if ($response == ''){
//time delay goes here
print "hello world";
}


Thanks

Mark
 
Thanks for you response but there is no time delay no matter how high I set $n to be.

Is there any way I could use set timeout or anything else?

Mark
 
easily done in javascript. is this a possibility?
 
possibly, but ideally PHP

Mark
 
i don't think it really works with php. there are too many variables (i.e. server configuration, browser sensitivities) etc.

you could have auto-refreshing pages with an incremental counter and then use php to redisplay each page with new text based on the countervalue?

e.g put this code dynamically into the <head> tags of each page on generation. The 10 is the number of seconds and the URL is the next page you want displayed.

Code:
<META HTTP-EQUIV="Refresh" CONTENT="10;URL=nextscreen.html">

to avoid the refresh look i'd seriously consider using javascript though. store the responses in a javascript var set (array?) and run a script that inserts the responses on predefined events like typing or time. lots of examples of this on the web.

hth
Justin
 
Code:
<?php

sleep(5);

echo "das";

?>

That should work. If it doesnt', then something is wrong with your server.
 
this does delay the script from the browser's perspective. but i have found that running php as an apache mod rather than a cgi means that
Code:
<?
echo "hello";
sleep(10);
echo "hello world";
?>

does not insert the delay. i have a feeling it would do if php were running as a cgi.

have also tried variations with ob_start() and ob_flush() but it makes no difference (at least in my installation...)
Justin
 
Does the script take 10 seconds to come back to you ?
 
mmm interesting, the entire script is waiting 10 seconds before being sent, I'm suprised that the ob_* functions don't help here. When you get coundtown games they are usualy CGI with someting i think is called NPH (non parsed headers). I might be totaly wrong here my memory is not too good, could you replicate the proboem in perl, which I know should work.
Could you post a sample with your called to the ob_ functions in please
 
this isn't my chain, really...! but i guess we're still discussion brogan's initial query.

here's what i tried with the ob_flush calls:

Code:
<?
ob_start();
echo "Hello World";
ob_flush();
sleep (20);
echo "Hellow World Again";
ob_end_flush();
?>

will have a go with perl when I have a mo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top