rklockner Posted July 7, 2020 Share Posted July 7, 2020 (edited) 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 July 7, 2020 by rklockner Quote Link to comment https://forums.phpfreaks.com/topic/311042-curl-not-working/ Share on other sites More sharing options...
maxxd Posted July 7, 2020 Share Posted July 7, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311042-curl-not-working/#findComment-1579410 Share on other sites More sharing options...
rklockner Posted July 7, 2020 Author Share Posted July 7, 2020 (edited) 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 July 7, 2020 by rklockner Quote Link to comment https://forums.phpfreaks.com/topic/311042-curl-not-working/#findComment-1579411 Share on other sites More sharing options...
rklockner Posted July 7, 2020 Author Share Posted July 7, 2020 (edited) 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 July 7, 2020 by rklockner Quote Link to comment https://forums.phpfreaks.com/topic/311042-curl-not-working/#findComment-1579412 Share on other sites More sharing options...
maxxd Posted July 7, 2020 Share Posted July 7, 2020 Is error reporting enabled on your new server? Granted it's early for me, but nothing in your sample code jumps out as being wrong. Quote Link to comment https://forums.phpfreaks.com/topic/311042-curl-not-working/#findComment-1579414 Share on other sites More sharing options...
rklockner Posted July 7, 2020 Author Share Posted July 7, 2020 (edited) 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 July 7, 2020 by rklockner Quote Link to comment https://forums.phpfreaks.com/topic/311042-curl-not-working/#findComment-1579415 Share on other sites More sharing options...
maxxd Posted July 8, 2020 Share Posted July 8, 2020 Yup - I'd've been no help at all there; glad you got it figured out, and thanks for posting the reason! Quote Link to comment https://forums.phpfreaks.com/topic/311042-curl-not-working/#findComment-1579431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.