{"id":9854,"date":"2022-05-10T00:20:16","date_gmt":"2022-05-09T16:20:16","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=9854"},"modified":"2023-09-25T09:30:48","modified_gmt":"2023-09-25T01:30:48","slug":"php-%e4%b8%a6%e8%a1%8c%e8%99%95%e7%90%86","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=9854","title":{"rendered":"PHP - \u4e26\u884c\u8655\u7406"},"content":{"rendered":"\r\n<p>--<\/p>\r\n\r\n\r\n\r\n<h2>popen, pclose<\/h2>\r\n\r\n\r\n\r\n<ul>\r\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/70855\" target=\"_blank\" rel=\"noopener\">How can one use multi threading in PHP applications<\/a><\/li>\r\n<li><a href=\"https:\/\/www.php.net\/manual\/zh\/function.popen.php\" target=\"_blank\" rel=\"noopener\">PHP: popen - Manual<\/a><\/li>\r\n<\/ul>\r\n\r\n<p>\u61c9\u7528\u5834\u666f\u70ba\u9700\u8981\u5927\u91cf\u4e0a\u50b3 HTTP\uff0c\u4e00\u822c\u8ff4\u5708\u8655\u7406\u4f9d\u5e8f\u9700\u8981\u6d6a\u8cbb\u6642\u9593\uff0c\u5982\u679c\u6c92\u6709\u9806\u5e8f\u95dc\u4fc2\u53ef\u4ee5\u4f7f\u7528\u300c\u4e26\u884c\u300d\u4f86\u5b8c\u6210\u3002<\/p>\r\n<p>\u4f7f\u7528\u8d77\u4f86\u5f88\u7c21\u55ae\uff0c\u6709\u4fb7\u9650\u6027\uff0c\u4e0d\u904e\u61c9\u7528\u5834\u666f\u53ef\u4ee5\u5957\u7528\u90a3\u7a0b\u5f0f\u5c31\u5f88\u7c21\u55ae\uff0c\u985e\u4f3c\u9019\u6a23\u5b50<\/p>\r\n<p>\u5fc5\u9808\u5148\u628a\u4e0a\u50b3\u7684\u7a0b\u5f0f\u62c6\u958b\u7368\u7acb\uff0c\u7136\u5f8c\u4f7f\u7528 popen() \u57f7\u884c<\/p>\r\n<pre class=\"lang:php decode:true \">&lt;?php\r\n$url = 'https:\/\/domain.name';\r\n$p = [];\r\n \r\nfor( $i=1; $i&lt;=20; $i++ ){\r\n    $p[$i] = popen('php \/opt\/Server\/WWW\/x\/http_upload.php '. $i .' '. $url . ' \"{}\"', 'w');\r\n}\r\n \r\n\/\/ \u5fc5\u9808\u6709\u6b64 pclose() \u8ff4\u5708\uff0c\u624d\u6703\u4e26\u884c\u8655\u7406\r\nfor( $i=1; $i&lt;=20; $i++ ) {\r\n    pclose($p[$i]);\r\n}<\/pre>\r\n<p>http_upload.php<\/p>\r\n<ul>\r\n<li><a href=\"https:\/\/www.php.net\/manual\/zh\/reserved.variables.argv.php\" target=\"_blank\" rel=\"noopener\">$argv<\/a><\/li>\r\n<\/ul>\r\n<pre class=\"lang:php decode:true\">&lt;?php\r\necho $argv[1].\"\\n\";\r\n \r\n$ch = curl_init();\r\ncurl_setopt($ch, CURLOPT_URL, $argv[2]);\r\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\r\ncurl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);\r\ncurl_setopt($ch, CURLOPT_TIMEOUT, 2);\r\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\r\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $argv[3]);\r\ncurl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application\/json'));\r\ncurl_exec ($ch);\r\n$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);\r\ncurl_close($ch);\r\n \r\necho $argv[1] .':'. $status_code.\"\\n\";<\/pre>\r\n<p>--<\/p><div class=\"pvc_clear\"><\/div><p class=\"pvc_stats all \" data-element-id=\"9854\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;4,051&nbsp;total views<\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>-- popen, pclos...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"9854\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;4,051&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[260],"tags":[53],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/9854"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9854"}],"version-history":[{"count":13,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/9854\/revisions"}],"predecessor-version":[{"id":12660,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/9854\/revisions\/12660"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}