I created a wordpress plugin in which on post publish I will call a function which will send a post request to my server with blog post ID,post head and URL.
Everything is working fine,but the 'publish_post' is very slow,as it waits for server response.I'm using PHP curl method for server connection.
I even tried
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 0.1);
But doesn't make any change in response delay.
function on_post_publish( $ID) {
$subject=get_the_title( $ID );
$url= get_permalink( $ID )
send_data_to_server($subject,$url,$ID);
}
add_filter( 'publish_post', 'on_post_publish', 10, 2 );
function send_data_to_server($subject,$client_url,$ID){
$url = "http://....../plugin.php";
$data="subject=".$subject."&url=".$client_url."&post_id=".$ID;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS,
$data);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 0.1);
$json_response = curl_exec($curl);
curl_close($curl);
}