本教程永久停更。 新教程Gitbook地址:https://www.gitbook.com/book/linkeddestiny/easy-swoole/details Github地址:https://github.com/LinkedDestiny/swoole-concise-guide
linkeddestiny / swoole-doc Goto Github PK
View Code? Open in Web Editor NEWswoole文档及入门教程
swoole文档及入门教程
本教程永久停更。 新教程Gitbook地址:https://www.gitbook.com/book/linkeddestiny/easy-swoole/details Github地址:https://github.com/LinkedDestiny/swoole-concise-guide
echo "Error: {$fp->errMsg}[{$fp->errCode}]\n";
ERROR zm_deactivate_swoole (ERROR 103): Fatal error: Call to undefined method swoole_server::addtimer() in **** on line 27
<?php
class TimerServer
{
private $serv;
public function __construct() {
$this->serv = new swoole_server("0.0.0.0", 9501);
$this->serv->set(array(
'worker_num' => 8,
'daemonize' => false,
'max_request' => 10000,
'dispatch_mode' => 2,
'debug_mode'=> 1 ,
));
$this->serv->on('WorkerStart', array($this, 'onWorkerStart'));
$this->serv->on('Connect', array($this, 'onConnect'));
$this->serv->on('Receive', array($this, 'onReceive'));
$this->serv->on('Close', array($this, 'onClose'));
// bind callback
$this->serv->on('Timer', array($this, 'onTimer'));
$this->serv->start();
}
public function onWorkerStart( $serv , $worker_id) {
// 在Worker进程开启时绑定定时器
echo "onWorkerStart\n";
// 只有当worker_id为0时才添加定时器,避免重复添加
if( $worker_id == 0 ) {
$serv->addtimer(100);
$serv->addtimer(500);
$serv->addtimer(1000);
}
}
public function onConnect( $serv, $fd, $from_id ) {
echo "Client {$fd} connect\n";
}
public function onReceive( swoole_server $serv, $fd, $from_id, $data ) {
echo "Get Message From Client {$fd}:{$data}\n";
}
public function onClose( $serv, $fd, $from_id ) {
echo "Client {$fd} close connection\n";
}
public function onTimer($serv, $interval) {
switch( $interval ) {
case 500: { //
echo "Do Thing A at interval 500\n";
break;
}
case 1000:{
echo "Do Thing B at interval 1000\n";
break;
}
case 100:{
echo "Do Thing C at interval 100\n";
break;
}
}
}
}
new TimerServer();
Fatal error: Uncaught Error: Call to undefined method swoole_server::addtimer()
vagrant@vagrant-ubuntu-trusty:/www/swoole$ make/www/swoole$
/bin/bash /home/vagrant/www/swoole/libtool --mode=compile cc -I. -I/home/vagrant/www/swoole -DPHP_ATOM_INC -I/home/vagrant/www/swoole/include -I/home/vagrant/www/swoole/main -I/home/vagrant/www/swoole -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/home/vagrant/www/swoole/include -DHAVE_CONFIG_H -Wall -pthread -g -O2 -c /home/vagrant/www/swoole/swoole.c -o swoole.lo
libtool: compile: cc -I. -I/home/vagrant/www/swoole -DPHP_ATOM_INC -I/home/vagrant/www/swoole/include -I/home/vagrant/www/swoole/main -I/home/vagrant/www/swoole -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/home/vagrant/www/swoole/include -DHAVE_CONFIG_H -Wall -pthread -g -O2 -c /home/vagrant/www/swoole/swoole.c -fPIC -DPIC -o .libs/swoole.o
In file included from /usr/include/php5/ext/spl/spl_iterators.h:27:0,
from /home/vagrant/www/swoole/swoole.c:28:
/usr/include/php5/ext/pcre/php_pcre.h:29:18: fatal error: pcre.h: No such file or directory
#include "pcre.h"
^
compilation terminated.
make: *** [swoole.lo] Error 1
vagrant@vagrant-ubuntu-trusty:
php -m 显示已经有swoole,说明是安装成功了。所以想测试swoole的echo服务器。执行Server代码出现如下错误:
PHP Warning: Cannot convert to ordinal value in /root/swoole/swooleServer.php on line 15
Warning: Cannot convert to ordinal value in /root/swoole/swooleServer.php on line 15
PHP Warning: Cannot convert to ordinal value in /root/swoole/swooleServer.php on line 15
Warning: Cannot convert to ordinal value in /root/swoole/swooleServer.php on line 15
Segmentation fault
Mac下使用cli_set_process_title报错:Warning: cli_set_process_title(): cli_set_process_title had an error: Not initialized correctly #616,查阅了相关资料,应该是mac下安全性的问题,不允许重命名进程名称。
我的解决方案是将manager进程的pid记录到sh文件中,直接用pid来reload,这样的话可以全平台通用:
public function onStart(swoole_server $serv ) {
@cli_set_process_title("reload_master");
$managerPid = $serv->manager_pid;
$shString = "echo \"Reloading...\"
kill -USR1 {$managerPid}
echo \"Reloaded\"";
file_put_contents('./reload_manager.sh', $shString);
}
这个示例根本不值得推荐,应该用共享内存的形式来维护一个mysql连接池,而不是多个进程的方式,非常耗内存!!
demo-src-Chatroom 输入完用户名后没有任何输出,同一台机器两个客户端,server这边提示客户端连接成功。没有任何报错输出,redis我这边也安装了。请问这个是哪里出的问题?谢谢。
swoole v 1.9.9
在编译安装时,执行make命令,得到了一条错误:
fatal error: 'config.h' file not found
请问怎么解决?
系统是最近更新的OSX 10.12
error: #error "Enable async_mysql support, But no mysqli or mysqlnd."
make: *** [swoole.lo] Error 1
我看你给你文件上传的例子里面没有写处理文件上传的逻辑
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.