Curl has stopped working for me.
I ran some updates on my AWS EC2 server yesterday so I have a feeling that is the cause but I can't figure it out.
I am mainly using Curl to add people to various mailchimp lists. None of these scripts are working now and I am getting browser errors about the connection not being secure:
"The page you are trying to view cannot be shown because the authenticity of the received data could not be verified."
I am also getting the following error in my apache error logs which looks related:
/usr/sbin/httpd: symbol lookup error: /usr/lib64/libnsssysinit.so: undefined symbol: PR_GetEnvSecure
CURL is installed etc (see screenshot) and when I use curl from the command line on my web server the remote server talks back to me… so there is no problem there.
Any assistance much appreciated.
Danny.
// Set API Key and list ID to add a subscriber
$api_key = 'api key';
$list_id = 'our list id';
$dc = 'data center';
/* ================
* DESTINATION URL
* ================
*/
$url = 'https://' . $dc . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/';
/* ================
* DATA SETUP
* ================
*/
$pfb_data = array(
'email_address' => 'some.email@gmail.com',
'status' => 'pending',
'merge_fields' => array(
'FNAME' => 'First Name',
'LNAME' => 'Last Name',
),
'interests' => array( 'Interest List ID' => true )
);
// Encode the data
$encoded_pfb_data = json_encode($pfb_data);
// Setup cURL sequence
$ch = curl_init();
/* ================
* cURL OPTIONS
* The tricky one here is the _USERPWD - this is how you transfer the API key over
* _RETURNTRANSFER allows us to get the response into a variable which is nice
* This example just POSTs, we don't edit/modify - just a simple add to a list
* _POSTFIELDS does the heavy lifting
* _SSL_VERIFYPEER should probably be set but I didn't do it here
* ================
*/
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $api_key);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encoded_pfb_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$results = curl_exec($ch); // store response
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE); // get HTTP CODE
$errors = curl_error($ch); // store errors
curl_close($ch);
// Returns info back to jQuery .ajax or just outputs onto the page
$results = array(
'results' => $result_info,
'response' => $response,
'errors' => $errors
);
// Sends data back to the page OR the ajax() in your JS
echo json_encode($results);
Best Answer
Apparently the problem was a recently published an update to the NSS package for CentOS 7 systems which was resulting in an Aache error
/usr/sbin/httpd: symbol lookup error: /lib64/libnsssysinit.so: undefined symbol: PR_GetEnvSecure
The issue was resolved by restarting the Apache and FPM services.
I resolved the problem by restarting my EC2 instance.