如何调试PHP cURL不会触发请求?

时间:2017-10-25 01:35:14

标签: php laravel http curl request

环境

  • PHP版本: PHP 5.6.21

  • cURL版本:卷曲7.29.0

  • 网络服务器: Nginx

  • Linux: Cent OS

描述

我在PHP中有这个CURL。

$headers = array(
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Basic " . $auth_code
);

$data = 'grant_type=authorization_code&code='.$code;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$AUTH_TOKEN_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
curl_setopt($ch, CURLOPT_USERAGENT,'php');
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$info = curl_getinfo($ch);
$result = curl_exec($ch);

我做了一个Wireshark捕获,我任何GET / POST请求启动。

有什么可能阻止它?

我还应该研究什么?

我已经尝试打印出这两个值

**dd($ch);**

I got  

"ch" => curl resource @10 ▼
    url: "https://www.web.com/oauth"
    content_type: null
    http_code: 0
    header_size: 0
    request_size: 0
    filetime: -1
    ssl_verify_result: 0
    redirect_count: 0
    total_time: 0.004216
    namelookup_time: 0.004148
    connect_time: 0.113475
    pretransfer_time: 0.0
    size_upload: 0.0
    size_download: 0.0
    speed_download: 0.0
    speed_upload: 0.0
    download_content_length: -1.0
    upload_content_length: -1.0
    starttransfer_time: 0.0
    redirect_time: 0.0
    redirect_url: ""
    primary_ip: "8.8.8.8"
    certinfo: []
    primary_port: 443
    local_ip: "10.0.129.127"
    local_port: 56907
}


**dd($info);** 

I got 

"info" => array:26 [▼
"url" => "https://www.web.com/oauth"
"content_type" => null
"http_code" => 0
"header_size" => 0
"request_size" => 0
"filetime" => 0
"ssl_verify_result" => 0
"redirect_count" => 0
"total_time" => 0.0
"namelookup_time" => 0.0
"connect_time" => 0.0
"pretransfer_time" => 0.0
"size_upload" => 0.0
"size_download" => 0.0
"speed_download" => 0.0
"speed_upload" => 0.0
"download_content_length" => -1.0
"upload_content_length" => -1.0
"starttransfer_time" => 0.0
"redirect_time" => 0.0
"redirect_url" => ""
"primary_ip" => ""
"certinfo" => []
"primary_port" => 0
"local_ip" => ""
"local_port" => 0
]
似乎没有什么用在那里。

问题

如何继续进行调试?

我现在对任何建议持开放态度。

任何提示/建议/帮助都将非常感谢!

2 个答案:

答案 0 :(得分:2)

SELinux阻止httpd进程建立网络连接。

setsebool -P httpd_can_network_connect 1

有关详细信息,请参阅httpd_selinux(8)手册页。

答案 1 :(得分:1)

如果您需要进一步调查,可以尝试strace

如果通过访问页面' /mycode.php'来触发此代码:

strace -tt -e trace=sendto,connect,open,write,read php /path/to/your/app/mycode.php

如果您的代码是通过框架执行的,或是通过诸如index.php:

之类的入口点处理的
HTTP_HOST=www.yourdomain.com REQUEST_URI=/mycode.php strace -tt -e trace=sendto,connect,open,write,read php /path/to/your/app/index.php

此输出应该能够指向您的问题来源(例如,某些文件未打开,proccesses not started)