{"id":1082,"date":"2010-12-20T16:11:31","date_gmt":"2010-12-20T07:11:31","guid":{"rendered":"http:\/\/uda2.com\/blog\/?p=1082"},"modified":"2010-12-20T16:11:31","modified_gmt":"2010-12-20T07:11:31","slug":"1082","status":"publish","type":"post","link":"https:\/\/uda2.com\/blog\/1082\/","title":{"rendered":"PHP\u3067\u8907\u6570\u306eURL\u3092404\u30c1\u30a7\u30c3\u30af\u3059\u308b\u95a2\u6570\u306e\u901f\u5ea6\u6bd4\u8f03"},"content":{"rendered":"<p>amazon\u306eAPI\u306a\u3093\u304b\u3092\u5229\u7528\u3057\u3066\u753b\u50cf\u306e\u30d1\u30b9\u3092\u53d6\u5f97\u3057\u4fdd\u5b58\u3057\u3066\u3044\u308b\u3068\u7a00\u306b\u753b\u50cf\u304c\u524a\u9664\u3055\u308c\u3066\u3057\u307e\u3063\u3066\u308b\u4e8b\u304c\u3042\u308b\u3002<br \/>\n\u6bce\u56de\u3001amazon\u306eAPI\u3092\u53e9\u304f\u69d8\u306b\u3057\u3066\u3082\u3044\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3051\u3069\u983b\u7e41\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068amazon\u306b\u6012\u3089\u308c\u308b\u304b\u3082\u3057\u308c\u306a\u3044\u3002<br \/>\n\u305d\u3053\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3059\u308b\u4e8b\u306b\u3057\u305f\u306e\u3060\u3051\u3069PHP\u306b\u306f\u8272\u3005\u95a2\u6570\u304c\u3042\u308b\u306e\u3067\u305d\u308c\u305e\u308c\u30c1\u30a7\u30c3\u30af\u3057\u3066\u307f\u305f\u3002<br \/>\n<!--more--><br \/>\n\u307e\u305a\u306fPHP\u3067\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u3080\u3068\u3044\u3046\u4e8b\u306b\u95a2\u3057\u3066\u306f\u4e00\u756a\u30e1\u30b8\u30e3\u30fc\u306a\u300cfile_get_contents\u300d\u3002<\/p>\n<pre><code>if (!$data = @file_get_contents($url)) echo '\u7121\u3044\u3088';<\/code><\/pre>\n<p>\u305d\u306e\u6b21\u306b\u30ed\u30fc\u30ab\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u306b\u3088\u304f\u4f7f\u3046\u304c\u5b9f\u304c\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3082\u8aad\u3081\u308b\u300cfopen\u300d\u3002<\/p>\n<pre><code>if (!$fp = @fopen($url, \"r\")) echo '\u7121\u3044\u3088';<\/code><\/pre>\n<p>PHP5\u304b\u3089\u4f7f\u3048\u308b\u69d8\u306b\u306a\u3063\u305fHTTP\u30d8\u30c3\u30c0\u30fc\u8aad\u307f\u7528\u95a2\u6570\u300cget_headers\u300d\u3002<\/p>\n<pre><code>$header = @get_headers($url);\r\nif(strpos($header[0], '404') !== false) echo '\u7121\u3044\u3088';<\/code><\/pre>\n<p>\u3053\u308c\u3082PHP5\u304b\u3089\u4f7f\u3048\u308b\u69d8\u306b\u306a\u3063\u305f\u5f37\u529b\u306a\u95a2\u6570\u300cCURL\u300d<\/p>\n<pre><code>$ch = curl_init($url);\r\ncurl_setopt($ch, CURLOPT_HEADER,         TRUE);\t\t\t\/\/ \u30d8\u30c3\u30c0\u30fc\u3042\u308a\r\ncurl_setopt($ch, CURLOPT_NOBODY,         TRUE);\t\t\t\/\/ \u672c\u6587\u306a\u3057\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);\t\t\/\/ \u8fd4\u7b54\u306f\u30c6\u30ad\u30b9\u30c8\u3067\r\ncurl_setopt($ch, CURLOPT_TIMEOUT, 2);\t\t\t\/\/ \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\r\n$res = curl_exec($ch); \r\n$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\nif ($httpCode == 404) echo '\u7121\u3044\u3088';<\/code><\/pre>\n<p>\u305d\u3057\u3066\u3001\u8907\u6570\u306e\u30a2\u30c9\u30ec\u30b9\u306b\u4e00\u6c17\u306b\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u308b\u672c\u547d\u306e\u300ccurl Multi\u300d<\/p>\n<pre><code>$mh = curl_multi_init();\r\n$ch_list = array();\/\/ Curl\u30cf\u30f3\u30c9\u30eb\r\nforeach($urls as $mykey => $url) {\r\n\t$ch_list[$mykey] = curl_init($url);\r\n\tcurl_setopt($ch_list[$mykey], CURLOPT_HEADER,         TRUE);\r\n\tcurl_setopt($ch_list[$mykey], CURLOPT_NOBODY,         TRUE);\r\n\tcurl_setopt($ch_list[$mykey], CURLOPT_RETURNTRANSFER, TRUE);\r\n\tcurl_setopt($ch_list[$mykey], CURLOPT_TIMEOUT, 2);\r\n\tcurl_multi_add_handle($mh, $ch_list[$mykey]);\r\n}\r\n$running = null;\r\ndo { curl_multi_exec($mh, $running); } while ( $running );\r\nforeach($urls as $mykey => $url) {\r\n\t$httpCode = curl_getinfo($ch_list[$mykey], CURLINFO_HTTP_CODE);\r\n\tif ($httpCode == 404) echo '\u7121\u3044\u3088';\r\n\tcurl_multi_remove_handle($mh, $ch_list[$mykey]);\r\n\tcurl_close($ch_list[$mykey]);\r\n}\r\ncurl_multi_close($mh);<\/code><\/pre>\n<p>\u203bsocket\u3067\u3082\u3044\u3051\u305d\u3046\u306a\u6c17\u304c\u3057\u305f\u304c\u3046\u307e\u304f\u52d5\u304b\u306a\u304b\u3063\u305f\u306e\u3067\u30d1\u30b9\u3057\u305f\u3002<\/p>\n<p>10\u30b3\u306eurl\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u30925\u56de\u8a08\u6e2c\u3057\u3066\u5e73\u5747\u3092\u51fa\u3057\u305f\u3002<br \/>\ncurl Multi\u30000.014\u79d2<br \/>\ncurl\u30000.105\u79d2<br \/>\nget_headers\u30000.161\u79d2<br \/>\nfopen\u30000.162\u79d2<br \/>\nfile_get_contents\u30000.278\u79d2<br \/>\n\u4e00\u4f4d\u306ecurl Multi\u306e\u9ad8\u901f\u3055\u304c\u76ee\u7acb\u3064\u3082\u3063\u3068\u500b\u6570\u304c\u5897\u3048\u308b\u3068\u3082\u3063\u3068\u5dee\u306f\u62e1\u304c\u308a\u305d\u3046\u3060\u3002<br \/>\namazon\u306f\u8272\u3093\u306a\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u3092\u5410\u304d200\u3068404\u306f\u308f\u304b\u308a\u6613\u3044\u304c\u3001\u3061\u3087\u3063\u3068\u8a70\u307e\u308b\uff08\u6df7\u3093\u3067\u308b\uff09\u3068403\u3092\u5410\u304d\u3053\u306e\u5834\u5408\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u306e\u304b\u7121\u3044\u306e\u304b\u5206\u304b\u3089\u306a\u3044\u3068\u8a00\u3046\u554f\u984c\u304c\u3042\u308b\u3002<br \/>\n\u3053\u308c\u3092\u8e0f\u307e\u3048\u308b\u3068\u3001\u6bd4\u8f03\u7684\u30a2\u30af\u30bb\u30b9\u306e\u5c11\u306a\u3044\u6642\u9593\u5e2f\u306b\u30b5\u30b5\u30c3\u3068\u30c1\u30a7\u30c3\u30af\u3059\u308b\u306a\u3089curl Multi\u3067\u6642\u9593\u3092\u9078\u3070\u305a\u30c1\u30a7\u30c3\u30af\u3059\u308b\u306a\u3089fopen\u3092\u4f7f\u3046\u306e\u304c\u5b89\u5168\u306a\u6c17\u3082\u3059\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>amazon\u306eAPI\u306a\u3093\u304b\u3092\u5229\u7528\u3057\u3066\u753b\u50cf\u306e\u30d1\u30b9\u3092\u53d6\u5f97\u3057\u4fdd\u5b58\u3057\u3066\u3044\u308b\u3068\u7a00\u306b\u753b\u50cf\u304c\u524a\u9664\u3055\u308c\u3066\u3057\u307e\u3063\u3066\u308b\u4e8b\u304c\u3042\u308b\u3002 \u6bce\u56de\u3001amazon\u306eAPI\u3092\u53e9\u304f\u69d8\u306b\u3057\u3066\u3082\u3044\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3051\u3069\u983b\u7e41\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068amazon\u306b\u6012\u3089\u308c\u308b\u304b\u3082\u3057<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[205],"tags":[81],"class_list":["post-1082","post","type-post","status-publish","format-standard","hentry","category-creatorsdiary","tag-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts\/1082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/comments?post=1082"}],"version-history":[{"count":3,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts\/1082\/revisions"}],"predecessor-version":[{"id":1085,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/posts\/1082\/revisions\/1085"}],"wp:attachment":[{"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/media?parent=1082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/categories?post=1082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/uda2.com\/blog\/wp-json\/wp\/v2\/tags?post=1082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}