• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run php script without hanging

#1
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;

    } 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.