utf8_encode()和curl_init()不能在PHP7上运行

时间:2016-06-30 07:07:20

标签: php nginx php-7

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

此存储库适用于Windows,但现在看来一些内置函数不再有效。我已经检查了文档,似乎没有任何函数被弃用。

这是我到目前为止发现的错误,代码段及其相应的错误消息:

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 config

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;
    }
}

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

2 个答案:

答案 0 :(得分:4)

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

1.需要通过以下命令在您的系统上安装utf8_encode/decode: -

php xml extension

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

它声明sudo apt-get install php7.0-xml 是与[tableView beginUpdates]; [tableView reloadRowsAtIndexPaths:@[self.expandedIndexPath] withRowAnimation:UITableViewRowAnimationBottom]; [tableView endUpdates]; 相关的功能,您必须通过以下命令安装系统: -

tintColor

重要提示: - 安装这些库包 重新启动 服务器后 ,以便 更改将反映 。感谢。

答案 1 :(得分:2)

utf8_encode()php xml extension下的curlcurl extension下的sudo apt-get install php7.0-curl 下的函数。

解决方案

sudo apt-get install php7.0-xml

LuisResult
相关问题