ugrás a tartalomhoz

Php - curl multi get content üres sztringet ad

inf · 2010. Nov. 11. (Cs), 00.44
Sziasztok!

Curl multival szedek le rss feedeket. A legtöbb feeddel nincs problémám, viszont van egy, ami kiakaszt. :D

Ezt adja:
  1. array  
  2.   'url' => string 'http://www.origo.hu//contentpartner/rss/hircentrum/origo.xml' (length=60)  
  3.   'content_type' => string 'text/xml' (length=8)  
  4.   'http_code' => int 200  
  5.   'header_size' => int 497  
  6.   'request_size' => int 91  
  7.   'filetime' => int -1  
  8.   'ssl_verify_result' => int 0  
  9.   'redirect_count' => int 0  
  10.   'total_time' => float 0.422  
  11.   'namelookup_time' => float 0.047  
  12.   'connect_time' => float 0.063  
  13.   'pretransfer_time' => float 0.063  
  14.   'size_upload' => float 0  
  15.   'size_download' => float 22920  
  16.   'speed_download' => float 54312  
  17.   'speed_upload' => float 0  
  18.   'download_content_length' => float -1  
  19.   'upload_content_length' => float -1  
  20.   'starttransfer_time' => float 0.094  
  21.   'redirect_time' => float 0  
CURLOPT_RETURNTRANSFER-el szedem, ami ugye azt eredményezi, hogy a curl_multi_exec sztringbe teszi a tartalmat ahelyett, hogy echozná. Na most ha hagyom echozni, akkor rendesen kiírja a feed tartalmát, viszont ha curl_multi_getcontent-el próbálom kinyerni a sztringet, akkor üreset kapok meg ugye a fenti infokat. Na most ugye a status 200, curl_error nincsen a size_download elég magas, a download_content_length mégis -1. Mitől lehet ez szerintetek?
 
1

Ezzel a kóddal szedem a

inf · 2010. Nov. 11. (Cs), 01.26
Ezzel a kóddal szedem a feedeket:
  1. public function reloadFeeds()  
  2. {  
  3.     //(connection timeout = timeout-200) for prevent cutting the feed data  
  4.     $connectionTimeout=$this->getTimeout()>200  
  5.         ?($this->getTimeout()-200)  
  6.         :1;  
  7.     $sessions=array();  
  8.     $downloader=curl_multi_init();  
  9.     foreach ($this->feeds as $feed)  
  10.     {  
  11.         if (!file_exists($feed->getFeedCacheFile()) || time()-filemtime($feed->getFeedCacheFile())>=$feed->getReloadTime()*60)  
  12.         {  
  13.             $session=curl_init();  
  14.             curl_setopt($session,CURLOPT_URL,$feed->getUrl());  
  15.             curl_setopt($session,CURLOPT_FAILONERROR,true);  
  16.             curl_setopt($session,CURLOPT_RETURNTRANSFER,true);  
  17.             curl_setopt($session,CURLOPT_FOLLOWLOCATION,true);  
  18.             curl_setopt($session,CURLOPT_CONNECTTIMEOUT_MS,$connectionTimeout);  
  19.             curl_setopt($session,CURLOPT_TIMEOUT_MS,$this->getTimeout());  
  20.             curl_multi_add_handle($downloader,$session);  
  21.             $sessions[$feed->getName()]=$session;  
  22.         }  
  23.     }  
  24.     if (count($sessions))  
  25.     {  
  26.         do  
  27.         {  
  28.             curl_multi_exec($downloader,$activeSessions);  
  29.             usleep(20000);  
  30.         }  
  31.         while($activeSessions>0);  
  32.           
  33.         foreach ($sessions as $name => $session)  
  34.         {  
  35.             $feed=$this->getFeed($name);  
  36.             //rss integrity pattern for checking if timeout cut the response  
  37.             $content=curl_multi_getcontent($session);  
  38.             if (curl_errno($session) || !preg_match($this->rssIntegrityPattern,$content))  
  39.             {  
  40. //you can log failures here  
  41.                 if (file_exists($feed->getFeedCacheFile()))  
  42.                 {  
  43.                     //rewrite the file last modified time (no "touch" function prior php 5.3.0)  
  44.                     $content=file_get_contents($feed->getFeedCacheFile());  
  45.                 }  
  46.                 else  
  47.                 {  
  48.                     $content=null;  
  49.                 }  
  50.             }  
  51.             else  
  52.             {  
  53.                 $content=iconv($feed->getEncoding(),$this->getDisplayEncoding(),$content);  
  54.                 $content=preg_replace($this->xmlDeclarationPattern,$this->xmlDeclaration,$content);  
  55.             }  
  56.             if ($content!=null)  
  57.             {  
  58.                 file_put_contents($feed->getFeedCacheFile(),$content);  
  59.             }  
  60.             curl_multi_remove_handle($downloader,$session);  
  61.             curl_close($session);   
  62.         }  
  63.     }  
  64.     curl_multi_close($downloader);  
  65. }  
2

Közben kiderült, hogy az

inf · 2010. Nov. 11. (Cs), 01.43
Közben kiderült, hogy az integritást néző regex hasal el, majd rákeresek, hátha van curl-es módszer is annak az ellenőrzésére, hogy teljesen átjött e az adat, vagy megszakította a timeout.
A probléma ott van, hogy iconv előtt ellenőrzöm az integritását egy latin2-es sztringnek 'u' módosítós regexel. Pff, látszik, hogy ideje aludni.