Php 卷曲错误:我无法在CodeIgniter 3中卷曲到本地URL
我最近将一个应用程序和环境从PHP5升级到PHP7,将Codeigniter 2升级到Codeigniter 3。但是,应用程序需要自我卷曲,而过去的工作方式现在给了我以下错误: 操作在30000毫秒后超时,接收到0字节 下面是代码,,我在一个外部URL上试用过,效果很好Php 卷曲错误:我无法在CodeIgniter 3中卷曲到本地URL,php,codeigniter,curl,codeigniter-3,Php,Codeigniter,Curl,Codeigniter 3,我最近将一个应用程序和环境从PHP5升级到PHP7,将Codeigniter 2升级到Codeigniter 3。但是,应用程序需要自我卷曲,而过去的工作方式现在给了我以下错误: 操作在30000毫秒后超时,接收到0字节 下面是代码,,我在一个外部URL上试用过,效果很好 $fullURL = 'http://localhost/andrew/index'; // create curl resource $ch = curl_init(); $curlOpt
$fullURL = 'http://localhost/andrew/index';
// create curl resource
$ch = curl_init();
$curlOpts = [
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_COOKIE => session_name() . '=' . session_id(),
CURLOPT_COOKIESESSION => true,
CURLOPT_REFERER => $domain.$_SERVER['REQUEST_URI'],
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'], // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => $timeout, // time-out on connect
CURLOPT_TIMEOUT => $timeout, // time-out on response,
CURLOPT_HTTPHEADER => [],
CURLOPT_SSL_VERIFYSTATUS => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSLVERSION => 3,
CURLOPT_URL => $fullURL,
];
if ($ajax) {
$curlOpts[CURLOPT_HTTPHEADER][] = 'X-Requested-With: XMLHttpRequest';
}
curl_setopt_array($ch, $curlOpts);
// $output contains the output string
$output = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$errors = curl_error($ch);
// close curl resource to free up system resources
curl_close($ch);
我认为这是一个应用程序问题,所以我制作了最基本的控制器来测试:
<?php
class Andrew extends CI_Controller
{
public function index()
{
die ('hello world');
}
}
. 这可能是一个安全风险!您似乎忽略了向我们(更重要的是您自己)展示在本地系统上运行时$fullURL是什么。。。在使用它之前的某个地方,一个var_转储($fullURL);对我们所有人都有效:)@Dharman,这不是安全风险,因为它只在本地部署URLs@TimBrownlaw我已经添加了一个示例url,但我已经在调试和手动请求中检查了它们。您的简单控制器测试没有证明cURL请求的可行性。尝试
类扩展CI_控制器{public function index(){echo'hello world';}}
并查看发生了什么。
class Andrew extends CI_Controller
{
public function __construct()
{
die('test'); // <-- cURL request resolves fine with this, $output = 'test'
parent::__construct();
}
public function index()
{
die ('hello world');
}
}
public function config($file, $use_sections = FALSE, $fail_gracefully = FALSE)
{
return get_instance()->config->load($file, $use_sections, $fail_gracefully); // <-- When a cURL request, get_instance()->config is a stdClass rather than an instance of `CI_Config`
}