/** * プールにアタッチされているリクエストを送信する * * @param HttpRequestPool $pool * @param P2HttpRequestQueue $queue * @return void */ public static function send(HttpRequestPool $pool, P2HttpRequestQueue $queue = null) { $err = ''; try { // キューからプールに追加 if ($queue && ($c = count($pool)) < self::MAX_REQUESTS) { while ($c < self::MAX_REQUESTS && ($req = $queue->pop())) { $pool->attach($req); $c++; } } // リクエストを送信 while ($c = count($pool)) { $pool->send(); // 終了したリクエストの処理 foreach ($pool->getFinishedRequests() as $req) { $pool->detach($req); $c--; if ($req instanceof P2HttpGet) { if ($req->hasError()) { $err .= sprintf('<li><em>%s</em>: %s</li>', htmlspecialchars($req->getUrl(), ENT_QUOTES), htmlspecialchars($req->getErrorInfo(), ENT_QUOTES)); } if ($req->hasNext()) { $pool->attach($req->getNext()); $c++; } } } // キューからプールに追加 if ($queue) { while ($c < self::MAX_REQUESTS && ($req = $queue->pop())) { $pool->attach($req); $c++; } } } } catch (HttpException $e) { $err .= sprintf('<li>%s (%d) %s</li>', get_class($e), $e->getCode(), htmlspecialchars($e->getMessage(), ENT_QUOTES)); } if ($err !== '') { $GLOBALS['_info_msg_ht'] .= "<ul class=\"errors\">{$err}</ul>\n"; } if (P2HTTPEXT_DEBUG) { if ($ph = http_persistent_handles_count()) { $ph_dump = str_replace(' ', ' ', print_r($ph, true)); $ph_dump = preg_replace('/[\\r\\n]+/', "\n", $ph_dump); $ph_dump = preg_replace('/(Array|Object)\\n *\\(/', '$1(', $ph_dump); $GLOBALS['_info_msg_ht'] .= "<pre>Persistent Handles:\n"; $GLOBALS['_info_msg_ht'] .= htmlspecialchars($ph_dump, ENT_QUOTES); $GLOBALS['_info_msg_ht'] .= "</pre>\n"; } } }
/** * Test Http functions. */ function test_functions() { http_cache_last_modified(); http_chunked_decode(); http_deflate(); http_inflate(); http_build_cookie(); http_date(); http_get_request_body_stream(); http_get_request_body(); http_get_request_headers(); http_match_etag(); http_match_modified(); http_match_request_header(); http_support(); http_negotiate_charset(); http_negotiate_content_type(); http_negotiate_language(); ob_deflatehandler(); ob_etaghandler(); ob_inflatehandler(); http_parse_cookie(); http_parse_headers(); http_parse_message(); http_parse_params(); http_persistent_handles_clean(); http_persistent_handles_count(); http_persistent_handles_ident(); http_get(); http_head(); http_post_data(); http_post_fields(); http_put_data(); http_put_file(); http_put_stream(); http_request_body_encode(); http_request_method_exists(); http_request_method_name(); http_request_method_register(); http_request_method_unregister(); http_request(); http_redirect(); http_send_content_disposition(); http_send_content_type(); http_send_data(); http_send_file(); http_send_last_modified(); http_send_status(); http_send_stream(); http_throttle(); http_build_str(); http_build_url(); }