urlgrabber fsock not timing out

Posts from previous Beta sessions

urlgrabber fsock not timing out

Postby poetter » Wed Jan 09, 2008 3:50 am

Hi,

it seems that the fsock part of urlgrabber is not timing out correctly.

The timeout in fsockopen only applies on connecting. See http://de.php.net/manual/en/function.fsockopen.php

timeout

The connection timeout, in seconds.

Note: If you need to set a timeout for reading/writing data over the socket, use stream_set_timeout(), as the timeout parameter to fsockopen() only applies while connecting the socket.


So i grabbed an example from here and implemented it into urlgrabber.

Here is the result:

Code: Select all
--- C:/Dokumente und Einstellungen/Daniel/Lokale Einstellungen/Temp/functions.lib.php-revBASE.svn000.tmp.php   Tue Jan 08 19:43:40 2008
+++ D:/xampp/roster.com/htdocs/lib/functions.lib.php   Tue Jan 08 19:43:26 2008
@@ -1226,15 +1226,18 @@
          }
          $header .= "\r\n";
          fwrite($file, $header);
+         stream_set_blocking($file, FALSE );
          stream_set_timeout($file, $timeout);
+
+         $info = stream_get_meta_data($file);
          $inHeader = true;
          $redirect = false;
          $resHeader = '';
          $tmp = '';
-         while( !feof($file) )
+         while( (!feof($file)) && (!$info['timed_out']) )
          {
             $chunk = fgets($file, 256);
-            1;
+            $info = stream_get_meta_data($file);
             if( $inHeader )
             {
                $pos = strpos($chunk, '<');
@@ -1254,6 +1257,9 @@
             $contents .= $chunk;
          }
          fclose($file);
+         if ($info['timed_out']) {
+            trigger_error("UrlGrabber Error [fsock] timed out", E_USER_WARNING);
+         }
          if( preg_match('/(?:Set-Cookie: )(.+)/', $resHeader, $tmp) )
          {
             $roster->cache->put($tmp[1], $cache_tag);
Image
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

urlgrabber fsock not timing out

Postby zanix » Wed Jan 09, 2008 10:35 am

Implemented svn[1575]
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US


Return to Archived

Who is online

Users browsing this forum: No registered users and 1 guest

cron