PDA

View Full Version : PHP: Timedelay between outputs!


pyro.699
02-23-2006, 09:16 AM
Hello everyone,
I have spent the last few weeks trying to get this small script to work, and it seemes verry simple. But, as we all know with php, looks can be deciving...

When you go to install a fresh copy of vbulletin, and it is at step 3 (or greater) and is adding the tables, and inserting info into the MySQL Database. How the vBulletin has designed the script, to show the completion srcipt:

echo "<li>$explain[$key]</li>\n";


# Creating access table
# Creating adminhelp table
# Creating administrator table
# Creating adminlog table
# Creating adminutil table
...


Now, if by chance, the script runs into an error, it halts the script, and then it displays an error... what i want to know, is how did the make the text appear, as the scripts were being run? I have made a script, that makes alot of files, and i would like it to display the files that it has created. Now i know that i could just take the easy way out and go:

$d = dir("./directory/");
while (false !== ($entry = $d->read()))
{
if ($entry == "." or $entry == "..")
{}
else
{
//Stuff for if the files name is not . or ..
}
}

But, I would like to know the ones that it has just made... So, putting it in simple terms, i want something like "sleep{};" , but NOT sleep(); with Sleep, it adds up the ammont in to one large sum, i want some to appear, before that happens.

Ok, i hope i have supplied you with enough information. Thankyou to any help in advanced
-Cody Woolaver

Marco van Herwaarden
02-23-2006, 09:25 AM
I really don't get what you are asking.

If you want to output lines before the page is finished, have a look into flush() and ob_flush(), or search the PHP documentation for Output Control Functions

pyro.699
02-24-2006, 12:45 AM
Ok, when you think about it, its actchually quite simple...

I am creating mass ammounts of files, (in the thousands(please don't ask what they're for)), and i have a script set up to do it all in one simple process. I want it to only display text as the file is displayed:

-File#1 gets made
-At the moment, the only text on the screen should be "Creating File #1: 5jd9ndio.djb" ---
-File#2 gets made
-Now since another file has been made mroe text has been added, so it should all say:

Creating File #1: 5jd9ndio.djb
Creating File #2: 7uq3yahv.djb

---
??What if??
-Ok, i make File #4 have an ileagle name (/ \ : * ? < > |)
-"5*d9|sj:/.djb"
-It should now say:

Creating File #1: 5jd9ndio.djb
Creating File #2: 7uq3yahv.djb
Creating File #3: 9di8digk.djb
Warning: file_put_contents(./5*d9|sj:/.djb) [function.file-put-contents]: failed to open stream: Invalid argument in [file.php] on line [line#]



...


So, putting all file making aside, i would like this to happen (pretend the quote boxxes is 1 .php file)
Start of Page->

B

2 Seconds Latter->

Bo

2 Seconds Latter->

Bob

2 Seconds Latter->

Bob

2 Seconds Latter->

Bob D

2 Seconds Latter->

Bob Di

2 Seconds Latter->

Bob Die

2 Seconds Latter->

Bob Died


Now rember there is a time delay :)

Andreas
02-24-2006, 12:52 AM
Checkout sleep()/usleep() and flush()

pyro.699
02-24-2006, 12:54 AM
I Did, it adds them up, ill give you part of my code...

$number = 0;
foreach ($songs as $filename)
{
$songname = "$filename";
$filename = "./ddrsongs/$filename.ddr";
if(file_exists($filename))
$variable = file_get_contents($filename);
$variable = "[$songname] - User Favorites:\n";
file_put_contents($filename, $variable);
$number = $number + 1;
// Rename For output
$before = array('[heart]', '[2]', '[star]', '[A]', '[coma]', '[q-mark]', '[e]');
$after = array('&hearts;', '<sup>2</sup>', '★', '&forall;', ',', '?', 'é');
$entry = str_replace($before['...'], $after['...'], $songname);
...
$output = " <li>Creating File #$number: $entry</li>\n";
echo $output;

}


:D Hey, umm, i just got it ^^;

sleep(1);
echo $output;
ob_flush();
flush();


thanks anyway ^^;