1
\$\begingroup\$

I wrote code which is doing query and insert inside while loop.

    $getall = mysql_query("SELECT `deviceid`,`uid` FROM  `users` WHERE FIND_IN_SET(`bgroup`,  '".$allbrgou."' ) AND `uid`!='".$from."'");
while($mdata = mysql_fetch_assoc($getall)){
        $newto = $mdata['uid'];

        $result = mysql_query("insert into request(rto,rfrom) values ($newto,$from)");


        $message="You get Request From ".$row['name'] ;
        $url = 'https://android.googleapis.com/gcm/send';
        $did=$mdata['deviceid'];

            $fields = array(
                            'registration_ids'  => array($did),
                            'data'              => array( "message" => $message ),
                            );
            $headers = array( 
                                'Authorization: key=xxxxxx',
                                'Content-Type: application/json'
                            );

            $ch = curl_init();
            curl_setopt( $ch, CURLOPT_URL, $url );
            curl_setopt( $ch, CURLOPT_POST, true );
            curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
            curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
            $result = curl_exec($ch);
            curl_close($ch);

}

This code on shared hosting took 2 min with just 120 records. Will concatenation and executing insert query fix this performance issue?

\$\endgroup\$
  • \$\begingroup\$ Does it work as intended? Have you tested this locally as well to make sure it's not simply your host messing up? \$\endgroup\$ – Mast Apr 19 '16 at 18:57
  • \$\begingroup\$ yeah code works fine seems curl takng time any way to solve it i am on shared hosting \$\endgroup\$ – saurav Apr 19 '16 at 19:01
  • \$\begingroup\$ Welcome to Code Review! I hope you get some good answers. \$\endgroup\$ – Phrancis Apr 19 '16 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.