Hi there. My (probably badly written code) is trying to read entries from a CSV file and, based on those entries decide if a script should be execute and, if so, how long to pause before execution. The script itself works - the data is read correctly into the array and I can check (echo) the fields without issue.
However, when I try to SLEEP() based on the the value from the file the script appears to JUST SLEEP without executing the echo commands. What I should see is a series of information about my csv file and then a sleep and then some more information. What I do see is just a long wait, then all the information at once.
I’ve tried using a static value in the sleep function (sleep(10)) but the same thing happens. It sleeps, then echos the information rather than echo/sleep/echo/sleep in a while loop.
For references $data[0] is a username, $data[1] is a password, $data[2] is whether or not to process the given entry, $data[3] is a % chance to execute the script and $data[4] is the delay (in seconds) before execution.
Any thoughts?
[php]<?php
$row = 1;
if (($handle = fopen(“my_test_file.csv”, “r”)) !== FALSE) {
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$num = count($data);
$row++;
if ($data[2]==="TRUE")
{
echo "user: $data[0] data execution is ON<br />\n";
echo "$data[0] chance to execute script is $data[3] <br />\n";
$t=rand(0, 100);
echo "execution random generator is $t<br />\n";
if ($t<$data[3])
{
echo “Will execute after a delay of $data[4] seconds<br / \n”;
sleep($data[4]);
}
}
else
{
echo “
”;
echo “Code will not be executed”;
echo “
”;
}
echo "<br />";
}
fclose($handle);
}
?>
[/php]