【问题标题】:utf8_encode() and curl_init() not working on PHP7utf8_encode() 和 curl_init() 在 PHP7 上不起作用
【发布时间】:2016-11-02 03:17:41
【问题描述】:

我刚刚从 Windows 过渡到 Ubuntu,我已经安装了 nginx、mysql、php7.0-fpm(包括 Opcache/ApcCache)的全新安装并从 git 克隆了一个项目(Yii2 项目)。

此存储库在 Windows 上工作,但现在似乎某些内置功能不再工作。我检查了文档,似乎没有任何功能被弃用。

这是我目前发现的错误,code-sn-ps 及其对应的错误信息:

curl_init()

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->getSlackPayloadUrl());
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);

调用未定义的函数 backend\components\curl_init()

utf8_encode()

$data = 'payload=' . json_encode(array_map("utf8_encode", [
            'channel'       =>  $channel,
            'text'          =>  $message,
        ]));

array_map() 期望参数 1 为有效回调,未找到函数 'utf8_encode' 或无效函数名

为了彻底,nginx 配置:

nginx 配置

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name project.dev;
    root        /var/www/project/backend/web;
    index       index.php;

    access_log  /var/www/project/log/access.log;
    error_log   /var/www/project/log/error.log;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        try_files $uri =404;
    }

    location ~* /\. {
        deny all;
    }
}

如果有任何其他相关信息,请添加评论,我会更新。

【问题讨论】:

标签: php nginx php-7


【解决方案1】:

根据我们的讨论,以下解决方案来了:-

1.需要通过命令在你的系统上安装CURL:-

sudo apt-get install php7.0-curl

2.关于第二个错误我得到了这个链接:-utf8_(en|de)code removed from php7?

它指出utf8_encode/decode 是与php xml extension 相关的功能,您必须通过以下命令安装系统:-

sudo apt-get install php7.0-xml

重要提示:-安装这些库包后重新启动您的服务器 以便反映。谢谢。

【讨论】:

    【解决方案2】:

    utf8_encode()php xml extension下的一个函数,curl当然是curl extension下的一个函数。

    解决者

    sudo apt-get install php7.0-curl
    

    sudo apt-get install php7.0-xml
    

    【讨论】:

    • 我在评论中添加了该链接,显示您的答案的第二部分被遗漏了。顺便说一句 +10
    猜你喜欢
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 2013-10-15
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    相关资源
    最近更新 更多