fclose($socket); function buildRequest($conn) { $request = new\stdClass(); $requestCommand = t 「 im(fgets($conn)); list ($request → method, $ 「 equest → path. $ 「 equest → ve 「 sion) = explode(). $ 「 equestCommand); while (($char = fgetc($conn)) ! = = false) { $line . = $cha 「 ; fo 「 each (explode("\n". $line) as $heade 「 ) { $label = strtouppe 「 (strt 「 ($tmp[l]. ・ $ 「 equest → $label = t 「 im($tmp[2]); if (isset($ 「 equest → CONTENT_LENGTH)) { $ 「 equest → body = f 「 ead($conn, intval($ 「 equst- >CONTENT_LENGTH)); b 「 eak; 「 etu 「 n $ 「 equest; 「これ、パイプの部分が良く分からないけど、なんとなく拡張子が " php " なら プログラムを起動するっていうところが、主な変更点だよね ? 」 「その通りだにや。パイプについては、 Linux の仕組の基本だから、そのうち こでは「プログラムとプログラムの間を通信する仕組」 説明するにや。一旦、 2 7
>path); fclose($conn); fwrite($conn. "HTTP/I.1 404 N0tFound\r\n"); } else { fw 「 ite($conn, $content); fwrite($conn, "\r\n"); fw 「 ite($conn, "Content-Type: text/html\r\n"); と、 png を返せるようになる 〃 HTML 固定にするよ。拡張子とかで判別して img/png とかにする fwrite($conn. "Content-Length:" . strlen($content) . "\ 「 \n"); fwrite($conn. "HTTP/I.1 200 OK\ 「 \n"); if ($content) { $content = file_get_contents($path); if ($ 「 equest → method = = ・ GET' & & is—file($path)) { 〃 GET で来ていて、ファイルが有ったら読む 2 0 ン explode( ・・ , $ 「 equestCommand); list ($ 「 equest → meth0d. $ 「 equest → path. $ 「 equest → ve 「 sion) = 〃スペース区切りでメソッド [GETIPOSTIDELETEIPUT] 、パス、パージョ $requestCommand = t 「 im(fgets($conn)); / / 1 行だけ読む、 1 行目はリクエスト内容そのもの $request = new\stdClass(); function buildRequest($conn) { fclose($socket);