utf8_encode() 和 curl_init() 不适用于 PHP7
utf8_encode() and curl_init() not working on PHP7
我刚刚从 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);
Call to undefined function backend\components\curl_init()
utf8_encode()
$data = 'payload=' . json_encode(array_map("utf8_encode", [
'channel' => $channel,
'text' => $message,
]));
array_map() expects parameter 1 to be a valid callback, function 'utf8_encode' not found or invalid function name
为了完整起见,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;
}
}
如果有任何其他相关信息,请添加评论,我会更新。
utf8_encode()
是 php xml extension
下的函数,curl
当然是 curl extension
.
下的函数
解决者
sudo apt-get install php7.0-curl
和
sudo apt-get install php7.0-xml
根据我们的讨论,得出以下解决方案:-
1.Need 通过命令在您的系统上安装 CURL
:-
sudo apt-get install php7.0-curl
2.Regarding 第二个错误我得到这个 link:-
它声明 utf8_encode/decode
是与 php xml extension
相关的功能,您必须通过以下命令安装系统:-
sudo apt-get install php7.0-xml
重要提示:- 安装这些库包后 重启 您的 服务器 这样 更改将反映 。谢谢。
我刚刚从 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);
Call to undefined function backend\components\curl_init()
utf8_encode()
$data = 'payload=' . json_encode(array_map("utf8_encode", [
'channel' => $channel,
'text' => $message,
]));
array_map() expects parameter 1 to be a valid callback, function 'utf8_encode' not found or invalid function name
为了完整起见,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;
}
}
如果有任何其他相关信息,请添加评论,我会更新。
utf8_encode()
是 php xml extension
下的函数,curl
当然是 curl extension
.
解决者
sudo apt-get install php7.0-curl
和
sudo apt-get install php7.0-xml
根据我们的讨论,得出以下解决方案:-
1.Need 通过命令在您的系统上安装 CURL
:-
sudo apt-get install php7.0-curl
2.Regarding 第二个错误我得到这个 link:-
它声明 utf8_encode/decode
是与 php xml extension
相关的功能,您必须通过以下命令安装系统:-
sudo apt-get install php7.0-xml
重要提示:- 安装这些库包后 重启 您的 服务器 这样 更改将反映 。谢谢。