免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3279 | 回复: 3
打印 上一主题 下一主题

难道phpinfo()取出的值不可信? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-25 09:35 |只看该作者 |倒序浏览
在phpinfo()函数中看到socket一段如下显示:
Sockets Support      enabled  

然后,试http://www.zend.com/pecl/tutorials/sockets.php 中的例程

  1. #!/usr/local/bin/php –q

  2. <?php
  3. // Set time limit to indefinite execution
  4. set_time_limit (0);

  5. // Set the ip and port we will listen on
  6. $address = 'localhost';
  7. $port = 9000;

  8. // Create a TCP Stream socket
  9. $sock = socket_create(AF_INET, SOCK_STREAM, 0);
  10. // Bind the socket to an address/port
  11. socket_bind($sock, $address, $port) or die('Could not bind to address');
  12. // Start listening for connections
  13. socket_listen($sock);

  14. /* Accept incoming requests and handle them as child processes */
  15. $client = socket_accept($sock);

  16. // Read the input from the client – 1024 bytes
  17. $input = socket_read($client, 1024);

  18. // Strip all white spaces from input
  19. $output = ereg_replace("[ \t\n\r]","",$input).chr(0);

  20. // Display output back to client
  21. socket_write($client, $output);

  22. // Close the client (child) socket
  23. socket_close($client);

  24. // Close the master sockets
  25. socket_close($sock);
  26. ?>

复制代码


按照
In order to run the program, make sure that the first line #!/usr/local/bin/php –q is the location of the PHP CLI (or CGI) binary. You will need to change the mode so it is executable (chmod 755 socket_server.php – where socket_server.php is the name of the file) and run it using ./socket_server.php from the command line.

来执行,竟然出错, 请见出错提示图

相反地,代码在同一服务器上,而用浏览器运行一段代码如下(从PHP manual中摘下)


  1. <?php
  2. error_reporting(E_ALL);

  3. echo "<h2>TCP/IP Connection</h2>\n";

  4. /* Get the port for the WWW service. */
  5. //$service_port = getservbyname('www', 'tcp');
  6. $service_port = 56753;

  7. /* Get the IP address for the target host. */
  8. //$address = gethostbyname('www.example.com');
  9. $address = "192.9.200.44" ;

  10. /* Create a TCP/IP socket. */
  11. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  12. if ($socket < 0) {
  13.     echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
  14. } else {
  15.     echo "OK.\n";
  16. }

  17. echo "Attempting to connect to '$address' on port '$service_port'...";
  18. $result = socket_connect($socket, $address, $service_port);
  19. if ($result < 0) {
  20.     echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
  21. } else {
  22.     echo "OK.\n";
  23. }

  24. $in = "HEAD / HTTP/1.1\r\n";
  25. $in .= "Host: www.example.com\r\n";
  26. $in .= "Connection: Close\r\n\r\n";
  27. $out = '';

  28. echo "Sending HTTP HEAD request...";
  29. socket_write($socket, $in, strlen($in));
  30. echo "OK.\n";

  31. echo "Reading response:\n\n";
  32. while ($out = socket_read($socket, 2048)) {
  33.     echo $out;
  34. }

  35. echo "Closing socket...";
  36. socket_close($socket);
  37. echo "OK.\n\n";
  38. ?>

复制代码


却是安然无恙,如下安然无恙图,phpinfo()中的Sockets Support  = enable是何意思?
何故致此? 还望高人指点迷津!

[ 本帖最后由 alinker 于 2006-4-25 09:40 编辑 ]

12.gif (12.52 KB, 下载次数: 29)

出错提示

出错提示

13.gif (9.73 KB, 下载次数: 26)

安然无恙

安然无恙

论坛徽章:
0
2 [报告]
发表于 2006-04-25 09:42 |只看该作者
如果说不能加载动态链接库"./sockets.so" , 无法运行socket_create函数,
那为何又能从browser端运行后面的那个socket程序, socket_create不出问题?

[ 本帖最后由 alinker 于 2006-4-25 09:46 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2006-04-25 11:31 |只看该作者
原帖由 52linux 于 2006-4-25 10:36 发表
php -m |grep -v Sockets

QQ 733905


php -m里没有Sockets模块内容, 但为何后面的socket程序可执行?

论坛徽章:
0
4 [报告]
发表于 2008-01-21 09:39 |只看该作者
那是你的/usr/local/bin/php 不是最新的php ,而apache中调用的是你重新编译过的php ,用新的php把/usr/local/bin/php覆盖掉
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP