【问题标题】:PHP Fatal error: Uncaught Error: Call to undefined function getheaders()PHP 致命错误:未捕获的错误:调用未定义的函数 getheaders()
【发布时间】:2017-10-07 10:58:49
【问题描述】:

当我运行我的代码时,我得到了这个错误

PHP 警告:log() 期望参数 1 为浮点数,字符串为 /opt/lampp/htdocs/x/websocket/server.php 第 2 行 PHP 致命错误: 未捕获的错误:调用未定义的函数 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)));

怎么了?

【问题讨论】:

    标签: php


    【解决方案1】:

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

    尝试使用 file_put_contents()。

    对于 getheaders(),正确的语法是“get_headers()”

    【讨论】:

    • 你的意思是使用 file_put_contents("Handshaking...");而不是这样的日志?我收到此错误 PHP 警告:file_put_contents() 需要至少 2 个参数,其中 1 个给出
    • 没有 file_put_contents($filepath, $content); => php.net/manual/en/function.file-put-contents.php 或者你可以使用 fopen()、fwrite() 和 fclose()。
    猜你喜欢
    • 2021-11-03
    • 1970-01-01
    • 2019-05-22
    • 2017-01-27
    • 2016-04-07
    • 2017-08-19
    相关资源
    最近更新 更多