1、curl_multi方法
当需要多线程的时候,可以用curl_multi一次性请求多个操作来完成,但curl走的是网络通信,效率与可靠性就比较差了的。
function main(){ $sql = "select waybill_id,order_id from waybill where status>40 order by update_time desc limit 10 "; $data = Yii::app()->db->createCommand($sql)->queryAll(); //yii 框架格式 foreach ($data as $k => $v) { if ($k % 2 == 0) { //偶数发一个网址 $send_data[$k]['url'] = ''; $send_data[$k]['body'] = $v['waybill_id']; } else { //奇数发送另外一个网址 $send_data[$k]['url'] = 'http://www.abc.com'; $send_data[$k]['body']=array($v['order_id'] => array('extra' => 16)); } } }
2、通过stream_socket_client 方式
function sendStream() { $english_format_number = number_format($number, 4, '.', ''); echo $english_format_number; exit(); $timeout = 10; $result = array(); $sockets = array(); $convenient_read_block = 8192; $host = "test.local.com"; $sql = "select waybill_id,order_id from xm_waybill where status>40 order by update_time desc limit 1 "; $data = Yii::app()->db->createCommand($sql)->queryAll(); $id = 0; foreach ($data as $k => $v) { if ($k % 2 == 0) { $send_data[$k]['body'] = NoticeOrder::getSendData($v['waybill_id']); } else { $send_data[$k]['body'] = array($v['order_id'] => array('extra' => 16)); } $data = json_encode($send_data[$k]['body']); $s = stream_socket_client($host . ":80