simplexml_load_fileã«timeoutãå©ç¨ãããå ´åã®ä»£æ¿æ¹æ³
simplexml_load_fileã¯ä¾¿å©ãªãã§ãããç´°ãããªãã·ã§ã³ã®è¨å®ãªã©ãã§ããªãã¦è¦å´ããäºãããã¾ãã
ä»åã¯ããç¨åº¦ã¬ã¹ãã³ã¹ãé
ãäºãäºæ¸¬ãããapiãå©ç¨ãã¦ããã®ã§ããããã¾ã«çµæããã®ã¾ã¾ãã¹ããã¦å¸°ã£ã¦ããªãäºãããã¾ããã
ãããprocessã¯responseãå¾
ã¡ç¶ããçµå±processããã£ã¨èµ°ãç¶ãã¡ããã¾ããã
69 $xml_data = simplexml_load_string($api_url); 70 if ($xml_data && count($xml_data->xpath('fault')) == 0) { 71 //å¦ç
curlã¨simplexml_load_stringã®ä½µç¨
simplexml_load_fileã®å©ç¨ããããããcurlã¨ã®ä½µç¨ã試ã¿ã¾ãã
63 // timeoutãè¨å®ããããã«ãcurlãå©ç¨ 64 $ch = curl_init($api_url); 65 curl_setopt($ch, CURLOPT_TIMEOUT, 300); 66 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 67 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // æ»ãå¤ãæåå㧠68 $xml_raw = curl_exec($ch); 69 $xml_data = simplexml_load_string($xml_raw); 70 if ($xml_data && count($xml_data->xpath('fault')) == 0) { 71 // å¦ç
curlã«éãããHTTP/Requestãªã©ã§ãããã§ãããconnectionç¨ã®timeoutã¨ãreadç¨ã®timeoutãããã®ã§ã注æãã
ç¹ã«çç±ããªããã°ã両æ¹è¨å®ãã¦ããã°è¯ããã¨ã
CURLOPT_RETURNTRANSFER ãè¨å®ããªãã¨ãcurl_execã®æ»ãå¤ã true ã«ãªã£ã¦ãã¾ãã¾ãã
æååãè¿ãã¦ããã£ã¦ãsimplexml_load_stringã§ãã¼ã¹ãã¾ãããã
stream_set_timeout
stream_set_timeoutãå©ç¨ããæ¹æ³ãããããã§ãã
Re: [PHP] simpleXML - simplexml_load_file() timeout? [Resolved]
stream_set_timeoutã®ã»ãã¯åä½ç¢ºèªãã¦ã¾ãããããã£ã¨åãããããªããã¨ãæ·¡ãæå¾ ã ãæ±ãã¦ã¾ãã