增加CLI判断、创建HTTP请求不再返回请求头

This commit is contained in:
TOP糯米 2019-10-11 20:10:44 +08:00
parent 5f9f9e2c12
commit d2977fd9ab
3 changed files with 17 additions and 4 deletions

View File

@ -65,7 +65,7 @@ class App
private static function initRoute() private static function initRoute()
{ {
$driver = null; $driver = null;
if (php_sapi_name() == 'cli') { if (Request::instance()->isCLI()) {
// 命令行运行程序 // 命令行运行程序
$driver = new Command(); $driver = new Command();
} else { } else {

View File

@ -160,10 +160,14 @@ function create_http_request($url, $data = [], $header = [])
curl_setopt($curl, CURLOPT_HEADER, $header); curl_setopt($curl, CURLOPT_HEADER, $header);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$res = curl_exec($curl); $response = curl_exec($curl);
if (!empty($header)) {
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$response = substr($response, $headerSize);
}
curl_close($curl); curl_close($curl);
if ($res) { if ($response) {
return $res; return $response;
} }
return false; return false;
} }

View File

@ -124,6 +124,15 @@ class Request
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
} }
/**
* CLI
* @return boolean
*/
public function isCLI()
{
return (php_sapi_name() == 'cli');
}
/** /**
* 创建一个请求post或get取决于data是否有值且不为空或空数组 * 创建一个请求post或get取决于data是否有值且不为空或空数组
* @param string $url * @param string $url