each time I run curl on php, the server will die. I have to restart the apache-Collection of common programming errors
Each time I run curl on php, the server will die. I have to restart the apache.
The code is the following: I am trying to connect to my notification server and push notifications.
I can, indeed, receive the notification, but the page with php-curl will never be open, and after that, my server will die(any pages can not be open, need to restart apache)
$url = 'http://myip:myport/send';
$fields = array(
'channel'=>urlencode("mychannel"),
'secretkey'=>urlencode("mypassword"),
'property1'=>urlencode("from PHP"),
'property2'=>urlencode("Hello jimmy!")
);
$fields_string = "";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
//close connection
curl_close($ch);
Supplement: It’s a Amazon’s EC2 server. also, i found that if i run curl in terminal, it not returning anything but it works properly.
-
I assume it is a Windows machine. Are you using XAMPP or WAMP? Google “php cURL crashes with windows” or your specific package, try to update your cURL extension. The code have nothing to do with your server crashing!