Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm writing a script that takes a list of several hundred URLs, file_get_contents the source and extracts the page's title.
Unfortunately, the script just stops running at random times (showing the page as 'Done').
By random, I mean that it will work perfectly for maybe 35 URLs one time, and then the next time I run it it will perform fine for perhaps 80 URLs. It never gets to the end of the test list that I'm using which has 137 entries.
I suspect that it may have something to do with pages loading very slowly, so instead of file_get_contents I used fread instead, setting the length parameter to 2000:Code: Select all
$handle = fopen($url, "r");
$head = fread($handle, 2000);
fclose($handle);I also tried to get clever with stream_set_timeout
Code: Select all
$handle = fopen($url, "r");
if (!$handle) {
echo "Unable to open\n";
} else {
stream_set_timeout($handle, 2);
$head = fread($handle, 2000);
$info = stream_get_meta_data($handle);
fclose($handle);
if ($info['timed_out']) {
echo "META TITLE = " . 'Connection timed out!'. "<br><hr>";
} else {
$title = gettitle($head);
echo "META TITLE = " . $title . "<br><hr>";
}Any ideas? I don't have much hair left and would love to salvage what is still there!
Martin
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]