是否可以将curl
拆分为3个部分?
例如,我有以下代码:
$headers = array(
"Content-Type:application/json",
"Authorization:key=" . self::ANDROID_AUTH_KEY
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
//result sample {"multicast_id":6375780939476727795,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1390531659626943%6cd617fcf9fd7ecd"}]}
//http://developer.android.com/google/gcm/http.html // refer error code
curl_close($ch);
在这种情况下,我希望有一个方法,例如:connect()
将curl_init()
执行一次,之后我想要一个方法send()
来调用{ {1}}然后将参数发布10次,然后发布将curl_exec()
disconnect()
的参数。
这是可能的吗?
请帮帮我。