Jump to content

cURL Not Working


rklockner

Recommended Posts

I have an integration with a third party that utilizes a SOAP API.  On my current server AND my local environment, this works fine.

I recently deployed a new server and it seems that cURL isn't doing anything.  *The code is identical on all three installations.

The "error" that I am seeing is no response at all (no response and no error, however, I can see that it is a "Resource").

After much trial and error, I tried creating a simple cURL example to test try to rule out other issues as the code itself is quite complex.  My simple example, that also fails, is as follows:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "google.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);
$err = curl_error($ch);

print_r($err);
echo $output;
curl_close($ch);

  This does the same thing.  On local, I get a "301 Moved" notice, on the new server, it is just a white screen.

I have confirmed that php has curl installed in via command line (php -m) and using phpinfo(); in my code.  It is definitely enabled.

What would cause cURL to not have a response AND not have an error?  My thought is a server setting, but I can't seem to find what might be causing this.

Edited by rklockner
Link to comment
Share on other sites

Check your cURL version across your environments. I had a similar issue once - Centos 6 uses an old version of cURL apparently, so everything I was doing locally and on the staging server worked perfectly but blew up completely on production until I manually updated the cURL version.

Link to comment
Share on other sites

15 minutes ago, maxxd said:

Check your cURL version across your environments. I had a similar issue once - Centos 6 uses an old version of cURL apparently, so everything I was doing locally and on the staging server worked perfectly but blew up completely on production until I manually updated the cURL version.

Thanks for the quick reply.  Doing a little research:

Locally (working): 7.53.1

Centos 7 (woking): 7.29.0

Centos 8 (not working): 7.61.1

Since the new server is running a more recent version, I feel like upgrading won't do the trick...

Edited by rklockner
Link to comment
Share on other sites

I just tried running the following in the command line on the new server and received the expected result, so it would seem that the version of curl is working, but there is an error with php?

$ curl google.com

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"><TITLE>301 Moved</TITLE></HEAD><BODY><H1>301 Moved</H1>The document has moved<A HREF="http://www.google.com/">here</A>.</BODY></HTML>

 

Edited by rklockner
Link to comment
Share on other sites

A friend of mine was able to clue me in, so I'd like to update with reason cURL wasn't working.

SELinux.

Once I disabled it, cURL worked fine.  I hope this helps someone!

EDIT: In the interest of the server being as secure as possible, a little research found that you can leave SELinux on, but run the following command to allow cURL traffic to pass through:

setsebool -P httpd_can_network_connect on

setsebool -P httpd_can_network_connect on

 

Edited by rklockner
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.