群晖 WebStation PHP curl 进行 http 请求(群晖 WebStation 安装第三方库)

Posted catoop

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了群晖 WebStation PHP curl 进行 http 请求(群晖 WebStation 安装第三方库)相关的知识,希望对你有一定的参考价值。

在群晖中,安装 WebStation 后,在安排配置 php 后,发现编写的 php 文件中有很多第三方库是无法适用的,运行就是 500 错误页面。

遇到这种情况,我们需要为 php 添加对应的脚本库,具体操作如下截图所示:


以截图中勾选 curl 为例,配置勾选配置前页面中是不能使用 curl 库进行 http 请求的,配置后即可正常使用。

如下 php 页面可以验证测试勾选 curl 库之前和之后是否能正常运行:

<?php

/**
 * 通过CURL进行GET请求
 */ 
function curl_get($url) 
	$header = array();
	
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_HEADER, 1)#我不需要获取头部啊;

    //设置头
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_USERAGENT,  'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/57.0.2987.98 Safari/537.36');
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 16);
    curl_setopt($ch, CURLOPT_TIMEOUT, 300);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    $output = curl_exec($ch);
    curl_close($ch);
    return  $output;


$res_html = curl_get("https://www.baidu.com");

print(res_html);

?>

如果你需要使用其他第三方库,对应勾选配置即可。


(END)

以上是关于群晖 WebStation PHP curl 进行 http 请求(群晖 WebStation 安装第三方库)的主要内容,如果未能解决你的问题,请参考以下文章