Here is a longer explanation and another possible cause for the problem.
I am extracting data from a site using a program called cURL (http://curl.haxx.se).
The reson for using curl is that the page is located behind a login-form using post and setting cookies, which curl handles for me.
What curl does, is that it grabs the source from a specified wepage using the command prompt. I write this data to a file using the passthru() function like this:
(The .html?action=1 changes up to fifty)
passthru("c:\curl\curl www.postsite.com/logged_in.html?action=1 > c:\curl\file.txt, $res);
I then read everything from this file and put it into a string ($html) like this:
$filename = "c:\curl\file.txt";
$fd = fopen ($filename, "r");
$html = fread ($fd, filesize ($filename));
fclose ($fd);
I then extract, lets say the different headlines and the body from this page.
For this I use some functions containing while-loops, which puts the values into the arrays $headline[] and $body[]. After this the second loop starts:
for ($j=0; $j<sizeof($headline); $j++) {
echo $headline[$j];
echo $body[$j];
}
When this is done the loop starts over and another page is written to file.txt etc.
The thing is that the second loop never reach the end of the string created from the file or come to think of it, maybe it is the while loops that doesn´t, although it works when I loop the entire thing twice and not fifty times.
Because it works when when I loop it twice I came to think of another possible fault. Perhaps my operating system can´t write and then read the same file 50 times over in 40 seconds. (I use win2000)
This is why I want to make sure that the whole contents of the webpage is written to the file and then read before doing another loop. Perhaps make a pause for two seconds before starting over so the OS can catch its breath...
Can PHP pause the script?
I haven´t seen anything about it, but who knows...
I hope I explained it better this time.
Thanks,
// Tobias Talltorp
-- Short explanation of the script, again:
first loop, 50 times {
get data to write into file;
write file.txt;
read file and put it into a string;
extract stuff from string and put each value in $array[];
loop sizeof($array) times {
echo $array[$number];
}
}