CodeIgniter Forums
Run php script without hanging - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Run php script without hanging (/showthread.php?tid=72321)



Run php script without hanging - omid_student - 12-04-2018

Hi
I have function that send push notification to users
When i use this function when user use it,it take 2 second for send push and user give result
While after execute send_push function,user have to receive result quickly
Do anyone have idea?

PHP Code:
function send_push($topic,$data,$is_android TRUE) {

        
//shell_exec("php test.php $topic '$data' > /dev/null 2>/dev/null &");

        
$api    =    config_item('firebase_api');

        
$fields = array
        (
            
'to'                 => "/topics/$topic",
            
'content_available'    =>    TRUE,
            
'data'                => $data
        
);

        if (!
$is_android)
            
$fields['notification']    =    $data;
        
        
$headers = array
        (
            
'Authorization: key=' $api,
            
'Content-Type: application/json'
        
);

        
$ch curl_init();
        
curl_setopt$ch,CURLOPT_URL'https://fcm.googleapis.com/fcm/send' );
        
curl_setopt$ch,CURLOPT_POSTtrue );
        
curl_setopt$ch,CURLOPT_HTTPHEADER$headers );
        
curl_setopt$ch,CURLOPT_RETURNTRANSFERtrue );
        
curl_setopt$ch,CURLOPT_SSL_VERIFYPEERfalse );
        
curl_setopt$ch,CURLOPT_POSTFIELDSjson_encode$fields ) );
        
$result curl_exec($ch );
        
curl_close$ch );
        return 
$result;

    }