2017-05-09 192 views
1

运行我的代码,我得到这个错误PHP致命错误:未捕获的错误:调用未定义功能getheaders()

PHP Warning: log() expects parameter 1 to be float, string given in /opt/lampp/htdocs/x/websocket/server.php on line 2 PHP Fatal error: Uncaught Error: Call to undefined function getheaders()

我的代码

<?php 
log("Handshaking..."); 
list($resource,$host,$origin) = getheaders($buffer); 
$upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" . 
      "Upgrade: WebSocket\r\n" . 
      "Connection: Upgrade\r\n" . 
      "WebSocket-Origin: " . $origin . "\r\n" . 
      "WebSocket-Location: ws://" . $host . $resource . "\r\n" . 
      "\r\n"; 
$handshake = true; 
socket_write($socket,$upgrade.chr(0),strlen($upgrade.chr(0))); 

有什么错?

回答

0

看看文档:http://php.net/manual/en/function.log.php日志不适用于“日志”。

尝试使用file_put_contents()。

为getheaders()正确的语法是 “get_headers()”

+0

你的意思是使用file_put_contents( “握手......”);而不是像那样的日志? 我得到这个错误PHP警告:file_put_contents()期望至少有2个参数,1给出 –

+0

否file_put_contents($ filepath,$ content); => http://php.net/manual/en/function.file-put-contents.php或者你可以使用fopen(),fwrite()和fclose()。 – Bast

相关问题