2017-05-09 106 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

相關問題