Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LinkedDestiny/swoole-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkedDestiny committed Nov 25, 2014
2 parents c8d11af + 666a8ce commit ec08fee
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 155 deletions.
4 changes: 2 additions & 2 deletions doc/02.swoole_server事件回调函数.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ $task_id | 任务ID
$from_id | 来自于哪个worker进程
$data | 任务内容

说明:在task_worker进程内被调用。worker进程可以使用swoole_server_task函数向task_worker进程投递新的任务。可以直接将任务结果字符串通过return方式返回给worker进程。worker进程将在[onFinish](#7onfinish)回调中收到结果。
说明:在task_worker进程内被调用。worker进程可以使用swoole_server_task函数向task_worker进程投递新的任务。可以直接将任务结果字符串通过return方式返回给worker进程。worker进程将在[onFinish](#7onfinish)回调中收到结果。注:如果serv->set(array('task_worker_num' => 8)) task_id 并不是从1-8 而是递增的。

####**7.onFinish**
描述:task_worker进程处理任务结束的回调<br>
Expand All @@ -154,7 +154,7 @@ $data | 任务结果
描述:定时器触发的回调<br>
函数原型:<br>
```php
function onFinish(swoole_server $serv, int $interval);
function onTimer(swoole_server $serv, int $interval);
```
参数 | 描述
-------- | ---------
Expand Down
2 changes: 1 addition & 1 deletion src/DBPool/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$db = new DB();
$db->connect($config[$key]);
for ($i = 0; $i <10000; $i++) {
$rs = $db->query("show tables;");
$rs = $db->query("select * from test;");
}
$db->release();

Expand Down
16 changes: 0 additions & 16 deletions src/DBPool/client2.php

This file was deleted.

1 change: 1 addition & 0 deletions src/DBPool/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'db_user' => 'root',
'db_pwd' => '123456',
'db_port' => '3306',
'pool_size' => '1',
)
);
?>
7 changes: 4 additions & 3 deletions src/DBPool/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ private function _makeCurKey($len = 8) {
}

function connect($config = array()) {
$this->_makeCurKey();
$this->send_data['cur_key'] = $this->cur_key;
//$this->_makeCurKey();
//$this->send_data['cur_key'] = $this->cur_key;
$this->send_data['param'] = array();
$this->config = $config;
$this->cli = new Client($this->config);
Expand All @@ -62,7 +62,8 @@ function __call($name, $arguments) {
}
}

function __desctruct() {
function __destruct() {
echo "db destruct release()\n";
$this->release();
}
}
Expand Down
49 changes: 11 additions & 38 deletions src/DBPool/db_client_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,55 +26,28 @@ public function connect() {
}

public function send($data) {
$need_recv = true;
if ($data['func_name'] == 'release') {
$need_recv = false;
}
if (is_array($data)) {
$data = json_encode($data);
}
echo "Send data: {$data} \n";
// echo "Send data: {$data} \n";
$rs = $this->client->send( $data );
$data = $this->client->recv();
if (!$data) {
for ($cnt = 0; $cnt < 1; $cnt++) {
$data = $this->client->recv();
if ($data) {
break;
}
if ($need_recv) {
$recv_data = $this->client->recv();
if (!$recv_data) {
echo " error_code:{$this->client->errCode}";
}
echo "receive faild! \n";
return false;
} else {
//echo "Client Recv data: ".var_dump($data)." \n";
echo "Client Recv data: ".$data." \n";

return $recv_data;
}
return $data;
}

public function isConnected() {
return $this->client->isConnected();
}
}

/*
function test_client() {
$client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
if (!$client->connect('127.0.0.1', 9500)) {
exit('client connect faild!');
}
for ($i = 0; $i < 5; $i++) {
$client->send(str_repeat($i,100));
$rs = $client->recv();
if ($rs === false) {
echo "recv faild \n";
break;
}
echo "recv[$i] ", $rs, " len:".strlen($rs)."\n";
}
$client->send("HELLO WORLD");
$data = $client->recv(9000,0);
var_dump($data);
$client->close();
unset($client);
}
test_client();
*/
?>
Loading

0 comments on commit ec08fee

Please sign in to comment.