{"id":900,"date":"2009-08-06T02:00:00","date_gmt":"2009-08-05T17:00:00","guid":{"rendered":"https:\/\/ecoop.net\/memo\/2009-08-06-2.html"},"modified":"2017-04-20T18:09:15","modified_gmt":"2017-04-20T09:09:15","slug":"2009-08-06-2","status":"publish","type":"post","link":"https:\/\/www.ecoop.net\/memo\/archives\/2009-08-06-2.html","title":{"rendered":"PHP\u3067\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u30c7\u30b9\u30af\u30ea\u30d7\u30bf\u3092\u958b\u304f"},"content":{"rendered":"<p>\nPHP \u306b\u306f fdopen \u304c\u306a\u3044\u306e\u3067\u3001\u5b50\u30d7\u30ed\u30bb\u30b9\u306b\u3064\u3044\u3066\u306f \/dev\/fd\/&lt;FD\u756a\u53f7> \u3067\u4ee3\u7528\u3057\u3066\u307e\u3059\u3002<br \/>\nPHP \u306e\u6a5f\u80fd\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3002\u3002<\/p>\n<blockquote><p>&lt;?php<br \/>\n\/\/ child.php: \u5b50\u30d7\u30ed\u30bb\u30b9(parent.php \u304b\u3089\u5b9f\u884c\u3055\u308c\u308b)<br \/>\n$fd = 4; \/\/ \u89aa\u30d7\u30ed\u30bb\u30b9\u3068\u306e\u3084\u308a\u53d6\u308a\u306b\u4f7f\u3046\u30d5\u30a1\u30a4\u30eb\u30c7\u30b9\u30af\u30ea\u30d7\u30bf(0:stdin, 1:stdout, 2:stderr)<br \/>\n$fdfile = &#8220;\/dev\/fd\/$fd&#8221;;<br \/>\nif(!file_exists($fdfile)){<br \/>\n&nbsp;&nbsp;&nbsp;die(&#8220;\u30d5\u30a1\u30a4\u30eb\u30c7\u30b9\u30af\u30ea\u30d7\u30bf\u304c\u958b\u304b\u308c\u3066\u3044\u307e\u305b\u3093&#8221;);<br \/>\n}<br \/>\n&nbsp;<br \/>\n$pipe = fopen($fdfile, &#8220;r&#8221;);<br \/>\nwhile(!feof($pipe)){<br \/>\n&nbsp;&nbsp;echo fread($pipe, 1024);<br \/>\n}<br \/>\nfclose($pipe);\n<\/p><\/blockquote>\n<p>&nbsp;\n<\/p>\n<blockquote><p>&lt;?php<br \/>\n\/\/ parent.php: \u89aa\u30d7\u30ed\u30bb\u30b9<br \/>\n$fd = 4; \/\/ \u5b50\u30d7\u30ed\u30bb\u30b9\u3068\u306e\u901a\u4fe1\u306b\u4f7f\u3046\u30d5\u30a1\u30a4\u30eb\u30c7\u30b9\u30af\u30ea\u30d7\u30bf<br \/>\n$fp = proc_open(&#8220;php child.php&#8221;, array(<br \/>\n&nbsp;&nbsp;$fd=>array(&#8216;pipe&#8217;, r),<br \/>\n),$pipes);<br \/>\n&nbsp;<br \/>\nfwrite($pipes[$fd], &#8220;Hello world!!&#8221;);<br \/>\nfclose($pipes[$fd]);<br \/>\n&nbsp;<br \/>\nproc_close($fp);\n<\/p><\/blockquote>\n<p>&nbsp;<br \/>\nFreeBSD \u306e\u5834\u5408\u3001\u6a19\u6e96\u3067\u306f \/dev\/fd \u306b 0,1,2 \u3057\u304b\u306a\u3044\u305f\u3081\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3002<br \/>\n\u6b21\u306e\u3088\u3046\u306b\u3057\u3066fdescfs \u3092 \/dev\/fd \u306b\u30de\u30a6\u30f3\u30c8\u3059\u308c\u3070\u30d7\u30ed\u30bb\u30b9\u3054\u3068\u306e\u30d5\u30a1\u30a4\u30eb\u30c7\u30b9\u30af\u30ea\u30d7\u30bf\u3092\u81ea\u52d5\u4f5c\u6210\u3057\u3066\u304f\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<blockquote><p># echo &#8220;fdescfs \/dev\/fd fdescfs rw 0 0&#8221; >> \/etc\/fstab<br \/>\n# mount \/dev\/fd\n<\/p><\/blockquote>\n<p>\u307e\u305f\u306f \/dev\/fd \u3092\u4f7f\u308f\u306a\u3044\u5b9f\u88c5\u306b\u7f6e\u304d\u63db\u3048\u308b\u4e8b\u3067\u3082\u52d5\u4f5c\u3057\u307e\u3059\u3002<br \/>\n\u3053\u306e\u5834\u5408\u3001\u30d5\u30a1\u30a4\u30eb\u30c7\u30b9\u30af\u30ea\u30d7\u30bf\u304c\u958b\u3044\u3066\u3044\u308b\u304b\u306e\u78ba\u8a8d\u306b\u306f fstat [-p PID] \u3092\u4f7f\u3046\u3068\u3044\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\n<\/p>\n<blockquote><p>\/\/ child.php: FreeBSD \u3067 devfs \u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306e\u4ee3\u66ff\u5b9f\u88c5\u3002<br \/>\n$fd = 4;<br \/>\n$pipe = popen(&#8216;cat < &amp;'.$fd, 'r');<br \/>\necho fread($pipe, 1024)<br \/>\npclose();\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u306b\u306f fdopen \u304c\u306a\u3044\u306e\u3067\u3001\u5b50\u30d7\u30ed\u30bb\u30b9\u306b\u3064\u3044\u3066\u306f \/dev\/fd\/&lt;FD\u756a\u53f7> \u3067\u4ee3\u7528\u3057\u3066\u307e\u3059\u3002 PHP \u306e\u6a5f\u80fd\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3002\u3002 &lt;?php \/\/ child.php: \u5b50\u30d7\u30ed\u30bb\u30b9(paren &hellip; <a href=\"https:\/\/www.ecoop.net\/memo\/archives\/2009-08-06-2.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">PHP\u3067\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u30c7\u30b9\u30af\u30ea\u30d7\u30bf\u3092\u958b\u304f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89,135],"tags":[20,32],"class_list":["post-900","post","type-post","status-publish","format-standard","hentry","category-web-dev","category-server","tag-linux","tag-php"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/comments?post=900"}],"version-history":[{"count":0,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/900\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media?parent=900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/categories?post=900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/tags?post=900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}