简体   繁体   中英

curl works on command line, not in PHP

I'm running Drupal 8 on a Fedora R 28 running Apache/2.4.39 with PHP 7.2.18. My php curl function is failing, but the command line test works fine.

curl shows up in phpinfo(), is defined in 20-curl.ini, and doesn't show any errors in any of the log files. I've tried two different SSL certs. Testing comes back with flying colors.

Protocols TLS 1.3 No TLS 1.2 Yes TLS 1.1 Yes TLS 1.0 Yes SSL 3 No SSL 2 No

All I get back is: cURL error (7): Couldn't connect to server

echo 'Curl: ', function_exists('curl_version') ? 'Enabled' : 'Disabled'

returns Enabled.

array(26) {
  ["url"]=>
  string(23) "http://www.example.com/"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(0)
  ["header_size"]=>
  int(0)
  ["request_size"]=>
  int(0)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.000437)
  ["namelookup_time"]=>
  float(0.004549)
  ["connect_time"]=>
  float(0)
  ["pretransfer_time"]=>
  float(0)
  ["size_upload"]=>
  float(0)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(0)
  ["download_content_length"]=>
  float(-1)
  ["upload_content_length"]=>
  float(-1)
  ["starttransfer_time"]=>
  float(0)
  ["redirect_time"]=>
  float(0)
  ["redirect_url"]=>
  string(0) ""
  ["primary_ip"]=>
  string(0) ""
  ["certinfo"]=>
  array(0) {
  }
  ["primary_port"]=>
  int(0)
  ["local_ip"]=>
  string(0) ""
  ["local_port"]=>
  int(0)
}
cURL error (7):
 Couldn't connect to server

Turns out I needed to enable outbound connections. Not sure why it wasn't needed for the command line calls. It was probably unset when I rebooted the server.

setsebool httpd_can_network_connect true

For more info:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM