0

Environment

  • PHP Version : PHP 5.6.21

  • cURL Version : curl 7.29.0

  • Web Server : Nginx

  • Linux : Cent OS


Description

I have this CURL in PHP.

$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);

I did a Wireshark capture, I don't any GET/POST requests initiating.

What could possibly prevent it?

What else should I look into?

I've tried print out these 2 values

**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
}

With:

**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
]

nothing seems to use in there.

12
  • Did you check the web server and system logs? Commented Oct 25, 2017 at 1:37
  • nginx logs ? or cent OS log ? Commented Oct 25, 2017 at 1:37
  • 1
    Either in /var/log/messages or via journalctl depending on the version of CentOS. Commented Oct 25, 2017 at 1:44
  • 1
    Create a PHP INFO file phpinfo.php with content below and on the server and load it on the browser - then search that info for curl <?php phpinfo(); ?> Commented Oct 25, 2017 at 1:58
  • 1
    Php - Debugging Curl - you can save curl error into the file. Look at $verbose = ... Commented Oct 25, 2017 at 2:22

2 Answers 2

2

SELinux is preventing the httpd process from making a network connection.

setsebool -P httpd_can_network_connect 1

See the httpd_selinux(8) man page for details.

Sign up to request clarification or add additional context in comments.

4 Comments

Is there any VM or linux details that I can share with u ?
/var/log/messages - is empty.
/var/log/nginx/access.log - is empty
Do I need to restart any kind of service after running your suggestion setsebool -P httpd_can_network_connect 1 ???
1

You could try strace if you need some further investigation.

If this code is triggered for example by visiting the page '/mycode.php':

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

If your code is executed through a framework or handled though an entry point such as 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

The output from this should be able to point you towards the source of the issue (eg, certain files not opening, proccesses not starting)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.