Heim >Backend-Entwicklung >PHP-Tutorial >请问个fopensocket的有关问题

请问个fopensocket的有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:01:591175Durchsuche

请教个fopensocket的问题

本帖最后由 php_aga 于 2014-07-04 15:42:52 编辑 本地WAPM环境,php.ini有打开allow_url_fopen = On
write.php
$fp = fsockopen('localhost',80,&$errno,&$errstr,5); 
if(!$fp)

echo "$errstr ($errno)
\n"; 

else
{
fputs($fp,"GET / HTTP/1.0\nHost: http://localhost/1.php");
fclose($fp);
}
?>
在localhost根目录下存在1.php,但测试运行write.php后,
发现1.php并没有被执行,单独执行1.php是可以运行
请问为什么?
试过把http://localhsot/1.php改为1.php也不行;过程中没提示无法创建套链接
------解决方案--------------------
$fp = fsockopen('localhost', 80, $errno, $errstr, 5); <br />if(!$fp) { <br />  echo "$errstr ($errno)<br />\n"; <br />}else {<br />  fputs($fp,"GET /1.php HTTP/1.0\r\nHost: localhost\r\nConnection: Close\r\n\r\n");<br />  while (!feof($fp)) {<br />    echo fgets($fp, 128);<br />  }<br />  fclose($fp);<br />}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn