PHP 如何发起异步请求
答案:1 悬赏:70 手机版
解决时间 2021-03-24 19:10
- 提问者网友:兔牙战士
- 2021-03-24 12:04
PHP 如何发起异步请求
最佳答案
- 五星知识达人网友:白昼之月
- 2021-03-24 13:02
class Analytics_SomeConsumer {
public function __construct() {
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_nonblock($this->socket);
socket_connect($this->socket, $this->host, $this->port);
$this->queue = array();
}
public function __destruct() {
$payload = json_encode($this->queue);
# ... // wait for socket to be writeable
socket_write($this->socket, $payload);
socket_close($this->socket);
}
public function track($item) {
array_push($this->queue, $item);
}
?>
public function __construct() {
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_nonblock($this->socket);
socket_connect($this->socket, $this->host, $this->port);
$this->queue = array();
}
public function __destruct() {
$payload = json_encode($this->queue);
# ... // wait for socket to be writeable
socket_write($this->socket, $payload);
socket_close($this->socket);
}
public function track($item) {
array_push($this->queue, $item);
}
?>
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯