├── README-Eng.md ├── src ├── readme.md ├── Demo │ ├── View │ │ ├── Test │ │ │ └── Test.html │ │ └── Welcome │ │ │ └── Welcome.html │ └── Service │ │ ├── HttpCall.php │ │ └── NovaCall.php ├── Model │ └── Index │ │ ├── GetDBData.php │ │ └── GetCacheData.php └── Controller │ ├── Test │ └── ExceptionController.php │ └── Index │ └── IndexController.php ├── public └── index.html ├── resource ├── sql │ ├── readme.md │ ├── demo.php │ └── deamon │ │ └── mak.php ├── config │ ├── readme.md │ ├── qatest │ │ └── README.md │ ├── test │ │ ├── README.md │ │ ├── debug.php │ │ ├── loadBalancing.php │ │ ├── monitor │ │ │ ├── sql.php │ │ │ └── trace.php │ │ ├── log.php │ │ ├── cookie.php │ │ ├── connection │ │ │ ├── redis.php │ │ │ ├── nova.php │ │ │ ├── mysql.php │ │ │ └── tcp.php │ │ ├── service_discovery.php │ │ ├── server.php │ │ └── registry.php │ ├── online │ │ ├── debug.php │ │ ├── loadBalancing.php │ │ ├── monitor │ │ │ ├── sql.php │ │ │ └── trace.php │ │ ├── log.php │ │ ├── cookie.php │ │ ├── connection │ │ │ ├── redis.php │ │ │ ├── nova.php │ │ │ ├── mysql.php │ │ │ └── tcp.php │ │ ├── service_discovery.php │ │ ├── server.php │ │ └── registry.php │ └── share │ │ ├── rewrite.php │ │ ├── table │ │ └── demo.php │ │ ├── route.php │ │ ├── cache │ │ └── test.php │ │ ├── middleware.php │ │ └── path.php ├── middleware │ └── middleware.php ├── cache │ └── demo │ │ ├── test.php │ │ └── session.php ├── kvstore │ └── demo.php └── config.php ├── init ├── ServerStart │ └── readme.md ├── WorkerStart │ └── readme.md └── app.php ├── bin ├── httpd └── server ├── README.md ├── .gitignore ├── composer.json ├── phpunit.xml └── LICENSE /README-Eng.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resource/sql/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /init/ServerStart/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /init/WorkerStart/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resource/config/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resource/config/qatest/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resource/config/test/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Demo/View/Test/Test.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resource/config/online/debug.php: -------------------------------------------------------------------------------- 1 | true, 5 | ]; -------------------------------------------------------------------------------- /resource/config/test/debug.php: -------------------------------------------------------------------------------- 1 | true, 5 | ]; -------------------------------------------------------------------------------- /resource/config/online/loadBalancing.php: -------------------------------------------------------------------------------- 1 | 'polling' 5 | ]; -------------------------------------------------------------------------------- /resource/config/online/monitor/sql.php: -------------------------------------------------------------------------------- 1 | "/tmp/sql.log" 5 | ]; -------------------------------------------------------------------------------- /resource/config/test/loadBalancing.php: -------------------------------------------------------------------------------- 1 | 'polling' 5 | ]; -------------------------------------------------------------------------------- /resource/config/test/monitor/sql.php: -------------------------------------------------------------------------------- 1 | "/tmp/sql.log" 5 | ]; -------------------------------------------------------------------------------- /resource/config/share/rewrite.php: -------------------------------------------------------------------------------- 1 | 'index/index/index' 5 | ]; -------------------------------------------------------------------------------- /resource/config/test/log.php: -------------------------------------------------------------------------------- 1 | 'log://info/debug.log?useBuffer=false&format=json', 5 | ]; -------------------------------------------------------------------------------- /resource/config/online/log.php: -------------------------------------------------------------------------------- 1 | 'log://info/debug.log?useBuffer=false&format=json', 5 | ]; -------------------------------------------------------------------------------- /resource/config/share/table/demo.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'TABLES', 6 | 'COLUMNS', 7 | ], 8 | ]; -------------------------------------------------------------------------------- /resource/config/test/monitor/trace.php: -------------------------------------------------------------------------------- 1 | true, 5 | "trace_class" => \Zan\Framework\Sdk\Trace\ZanTracer::class 6 | ]; -------------------------------------------------------------------------------- /resource/config/online/monitor/trace.php: -------------------------------------------------------------------------------- 1 | false, 5 | "trace_class" => \Zan\Framework\Sdk\Trace\ZanTracer::class 6 | ]; -------------------------------------------------------------------------------- /resource/config/share/route.php: -------------------------------------------------------------------------------- 1 | '/index', 5 | 'default_controller' => 'index', 6 | 'default_action' => 'index', 7 | 'default_format' => 'html', 8 | ]; -------------------------------------------------------------------------------- /bin/httpd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | createHttpServer(); 8 | $server->start(); 9 | 10 | -------------------------------------------------------------------------------- /resource/middleware/middleware.php: -------------------------------------------------------------------------------- 1 | [ 5 | 6 | ], 7 | 'match' => [ 8 | ['/market\/.*/', 'acl'], 9 | ['/goods\/.*/', 'acl'], 10 | ['/shop\/.*/', 'acl'], 11 | ], 12 | ]; -------------------------------------------------------------------------------- /resource/cache/demo/test.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'connection' => 'redis.default_write', 6 | ], 7 | 'some_tpl' => [ 8 | 'key' => 'test_abc_%s_%s', 9 | 'exp' => 10 10 | ], 11 | ]; -------------------------------------------------------------------------------- /resource/config/test/cookie.php: -------------------------------------------------------------------------------- 1 | '.example.com', 5 | 'path' => '/', 6 | 'expire' => 2592000, 7 | 'secure' => FALSE, 8 | 'httponly' => FALSE, 9 | 'salt' => '', 10 | 'xss_filtering' => FALSE, 11 | ]; -------------------------------------------------------------------------------- /resource/config/online/cookie.php: -------------------------------------------------------------------------------- 1 | '.example.com', 5 | 'path' => '/', 6 | 'expire' => 2592000, 7 | 'secure' => FALSE, 8 | 'httponly' => FALSE, 9 | 'salt' => '', 10 | 'xss_filtering' => FALSE, 11 | ]; -------------------------------------------------------------------------------- /init/app.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'connection' => 'redis.default_write', 6 | ], 7 | 8 | 'session' => [ 9 | 'key' => 'PHPREDIS_SESSION:%s', 10 | 'exp' => 3600 * 24, 11 | ], 12 | ]; -------------------------------------------------------------------------------- /resource/config/share/cache/test.php: -------------------------------------------------------------------------------- 1 | 'redis.default_write', 10 | 'test' => [ 11 | 'key' => 'test_abc' 12 | ], 13 | ]; -------------------------------------------------------------------------------- /resource/kvstore/demo.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'connection' => 'kvstore.default', // 对应 connection/kvstore.php中配置 6 | ], 7 | 'cc' => [ 8 | 'key' => 'pic_ad_%d', 9 | 'exp' => 10, 10 | 'namespace' => 'youzan', 11 | 'set' => 'aaaatest' 12 | ], 13 | ]; -------------------------------------------------------------------------------- /resource/config/share/middleware.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'acl' => [ 6 | // XXX\Middleware\AclFilter::class, 7 | ], 8 | 9 | ], 10 | 'match' => [ 11 | ['/market\/.*/', 'acl'], 12 | ['/goods\/.*/', 'acl'], 13 | ['/shop\/.*/', 'acl'], 14 | ], 15 | ]; -------------------------------------------------------------------------------- /resource/config/share/path.php: -------------------------------------------------------------------------------- 1 | 'resource/sql/', 5 | 'log_path' => 'resource/log/', 6 | 'cache_path' => 'resource/cache/', 7 | 'model_path' => 'resource/model/', 8 | 'table_path' => 'resource/config/share/table/', 9 | 'connection_path' => 'resource/config/dev/connection/', 10 | ]; -------------------------------------------------------------------------------- /src/Demo/Service/HttpCall.php: -------------------------------------------------------------------------------- 1 | get("/data/sk/101110101.html"); 13 | } 14 | } -------------------------------------------------------------------------------- /src/Model/Index/GetDBData.php: -------------------------------------------------------------------------------- 1 | 2 13 | ]; 14 | //demo.demo_sql_id1_1对应resource/sql/demo.php中的配置 15 | yield Db::execute("demo.demo_sql_id1_1", $data); 16 | } 17 | } -------------------------------------------------------------------------------- /src/Model/Index/GetCacheData.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'engine'=> 'redis', 7 | 'host' => '127.0.0.1', 8 | 'port' => 6379, 9 | 'pool' => [ 10 | 'maximum-connection-count' => 50, 11 | 'minimum-connection-count' => 2, 12 | 'heartbeat-time' => 35000, 13 | 'init-connection'=> 2, 14 | ], 15 | ], 16 | ]; 17 | -------------------------------------------------------------------------------- /resource/config/test/connection/redis.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'engine'=> 'redis', 7 | 'host' => '127.0.0.1', 8 | 'port' => 6379, 9 | 'pool' => [ 10 | 'maximum-connection-count' => 50, 11 | 'minimum-connection-count' => 10, 12 | 'heartbeat-time' => 35000, 13 | 'init-connection'=> 2, 14 | ], 15 | ], 16 | ]; 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZanHttpDemo 2 | zan php http server demo 3 | 4 | # 如何使用 5 | 6 | 1. 安装 [*zan扩展*](https://github.com/youzan/zan),编译参数:(`sockets` 与 `openssl` 可选) 7 | `./configure --enable-sockets --enable-openssl` 8 | 2. 安装[composer](curl -sS https://getcomposer.org/installer | php) 9 | 3. 在根目录下执行composer update 10 | 4. 配置php.ini 11 | ```ini 12 | zanphp.RUN_MODE = test 13 | zanphp.DEBUG = true 14 | ``` 15 | 5. 启动http server 16 | `php bin/httpd` 17 | 6. 访问`127.0.0.1:8030` -------------------------------------------------------------------------------- /resource/config.php: -------------------------------------------------------------------------------- 1 | APP_PATH . '/resource/config', 7 | 'cache_path' => APP_PATH . '/resource/cache', 8 | 'sql_path' => APP_PATH . '/resource/sql', 9 | 'pre_filter_path' => APP_PATH . '/init/PreFilter', 10 | 'post_filter_path' => APP_PATH . '/init/PostFilter', 11 | 'routing_path' => APP_PATH . '/init/routing', 12 | ]; -------------------------------------------------------------------------------- /resource/config/online/connection/nova.php: -------------------------------------------------------------------------------- 1 | 'novaClient', 5 | 'timeout' => 5000, 6 | 'persistent' => true, 7 | 'heartbeat-time' => 30000, 8 | 'load_balancing_strategy' => 'polling', 9 | 'config' => [ 10 | 'open_length_check' => 1, 11 | 'package_length_type' => 'N', 12 | 'package_length_offset' => 0, 13 | 'package_body_offset' => 0, 14 | 'open_nova_protocol' => 1 15 | ], 16 | ]; -------------------------------------------------------------------------------- /resource/config/test/connection/nova.php: -------------------------------------------------------------------------------- 1 | 'novaClient', 5 | 'timeout' => 5000, 6 | 'persistent' => true, 7 | 'heartbeat-time' => 30000, 8 | 'load_balancing_strategy' => 'polling', 9 | 'config' => [ 10 | 'open_length_check' => 1, 11 | 'package_length_type' => 'N', 12 | 'package_length_offset' => 0, 13 | 'package_body_offset' => 0, 14 | 'open_nova_protocol' => 1 15 | ], 16 | ]; -------------------------------------------------------------------------------- /resource/config/online/connection/mysql.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'engine'=> 'mysqli', 6 | 'host' => '127.0.0.1', 7 | 'user' => 'root', 8 | 'password' => '123456', 9 | 'database' => 'information_schema', 10 | 'port' => 3306, 11 | 'pool' => [ 12 | 'maximum-connection-count' => 50, 13 | 'minimum-connection-count' => 2, 14 | 'heartbeat-time' => 5000, 15 | 'init-connection'=> 2, 16 | ], 17 | ], 18 | ]; -------------------------------------------------------------------------------- /resource/config/test/connection/mysql.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'engine'=> 'mysqli', 6 | 'host' => '127.0.0.1', 7 | 'user' => 'root', 8 | 'password' => '123456', 9 | 'database' => 'information_schema', 10 | 'port' => 3306, 11 | 'pool' => [ 12 | 'maximum-connection-count' => 50, 13 | 'minimum-connection-count' => 5, 14 | 'heartbeat-time' => 5000, 15 | 'init-connection'=> 5, 16 | ], 17 | ], 18 | ]; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | !t/ 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | pids 10 | logs 11 | node_modules 12 | *.sqlite 13 | .DS_Store 14 | .DS_Store? 15 | ._* 16 | .Spotlight-V100 17 | .Trashes 18 | ehthumbs.db 19 | Thumbs.db 20 | .idea/ 21 | iron.iml 22 | *.sublime-workspace 23 | *.sublime-project 24 | /nbproject/ 25 | .tm_properties 26 | .tags 27 | .tags_sorted_by_file 28 | .buildpath 29 | .project 30 | .settings/ 31 | .externalToolBuilders/ 32 | .sass-cache 33 | /xhprof* 34 | .vagrant 35 | composer.lock 36 | /vendor 37 | .private/ 38 | -------------------------------------------------------------------------------- /resource/config/test/service_discovery.php: -------------------------------------------------------------------------------- 1 | [ 7 | "tcp-demo" 8 | ], 9 | 10 | "novaApi" => [ 11 | "tcp-demo" => [ 12 | "path" => "vendor/nova-service/nova-demo/sdk/gen-php", 13 | "namespace" => "Com\\Yourcompany\\Demo\\", 14 | ] 15 | ], 16 | 17 | "connection" => [ 18 | "tcp-demo" => [ 19 | "host" => "127.0.0.1", 20 | "port" => 8100, 21 | ], 22 | ], 23 | */ 24 | ]; -------------------------------------------------------------------------------- /resource/config/online/service_discovery.php: -------------------------------------------------------------------------------- 1 | [ 8 | "tcp-demo" 9 | ], 10 | 11 | "novaApi" => [ 12 | "tcp-demo" => [ 13 | "path" => "vendor/nova-service/nova-demo/sdk/gen-php", 14 | "namespace" => "Com\\Yourcompany\\Demo\\", 15 | ] 16 | ], 17 | 18 | "connection" => [ 19 | "tcp-demo" => [ 20 | "host" => "127.0.0.1", 21 | "port" => 8100, 22 | ], 23 | ], 24 | */ 25 | ]; -------------------------------------------------------------------------------- /src/Demo/View/Welcome/Welcome.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Welcome to ZanPHP! 5 | 12 | 13 | 14 |

Welcome to ZanPHP!

15 |

If you see this page, the zanphp web server is successfully installed and 16 | working. Further configuration is required.

17 | 18 |

For online documentation and support please refer to 19 | zanphp.io.

20 | 21 |

Thank you for using zanphp.

22 | 23 | -------------------------------------------------------------------------------- /resource/config/test/connection/tcp.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'engine'=> 'tcp', 6 | 'host' => '127.0.0.1', 7 | 'port' => 2280, 8 | 'timeout' => 5000, 9 | 'hasRecv' => false, 10 | 'config' => [ 11 | 'open_length_check' => 1, 12 | 'package_length_type' => 'N', 13 | 'package_length_offset' => 0, 14 | 'package_body_offset' => 0, 15 | 'open_nova_protocol' => 1 16 | ], 17 | 'pool' => [ 18 | 'maximum-connection-count' => 5, 19 | 'minimum-connection-count' => 2, 20 | 'init-connection'=> 2, 21 | ], 22 | ], 23 | ]; 24 | -------------------------------------------------------------------------------- /resource/config/online/connection/tcp.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'engine'=> 'tcp', 6 | 'host' => '127.0.0.1', 7 | 'port' => 2280, 8 | 'timeout' => 5000, 9 | 'hasRecv' => false, 10 | 'config' => [ 11 | 'open_length_check' => 1, 12 | 'package_length_type' => 'N', 13 | 'package_length_offset' => 0, 14 | 'package_body_offset' => 0, 15 | 'open_nova_protocol' => 1 16 | ], 17 | 'pool' => [ 18 | 'maximum-connection-count' => 5, 19 | 'minimum-connection-count' => 2, 20 | 'init-connection'=> 2, 21 | ], 22 | ], 23 | ]; 24 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zanphp/httpdemo", 3 | "repositories": { 4 | "packagist": { 5 | "type": "composer", 6 | "url": "https://packagist.phpcomposer.com" 7 | } 8 | }, 9 | "require": { 10 | "zanphp/zan": "dev-master", 11 | "nova-service/nova-demo": "dev-master" 12 | }, 13 | "autoload": { 14 | "psr-4": { 15 | "Com\\Youzan\\ZanHttpDemo\\": "src", 16 | "Com\\Youzan\\ZanHttpDemo\\Init\\": "init" 17 | } 18 | }, 19 | "config": { 20 | "preferred-install": "dist", 21 | "secure-http": false 22 | }, 23 | "prefer-stable": false, 24 | "minimum-stability": "dev" 25 | } 26 | -------------------------------------------------------------------------------- /resource/config/test/server.php: -------------------------------------------------------------------------------- 1 | '0.0.0.0', 5 | 'port' => 8030, 6 | 'config' => [ 7 | 'worker_num' => 2, 8 | 'dispatch_mode' => 3, 9 | ], 10 | 'monitor' =>[ 11 | 'max_request' => 100000, // 12 | 'max_live_time' => 1800000, //30m 13 | 'check_interval'=> 10000, //1s 14 | 'memory_limit' => 1.5 * 1024 * 1024 * 1024, //1.50G 15 | 'cpu_limit' => 70, 16 | 'debug' => false 17 | ], 18 | 'request_timeout' => 30 * 1000, 19 | 'session' => [ 20 | 'run' => true, 21 | 'store_key' => 'demo.session.session', 22 | ], 23 | ]; -------------------------------------------------------------------------------- /resource/config/online/server.php: -------------------------------------------------------------------------------- 1 | '0.0.0.0', 5 | 'port' => 8030, 6 | 'config' => [ 7 | 'worker_num' => 2, 8 | 'dispatch_mode' => 3, 9 | ], 10 | 'monitor' =>[ 11 | 'max_request' => 100000, // 12 | 'max_live_time' => 1800000, //30m 13 | 'check_interval'=> 10000, //1s 14 | 'memory_limit' => 1.5 * 1024 * 1024 * 1024, //1.50G 15 | 'cpu_limit' => 70, 16 | 'debug' => false 17 | ], 18 | 'request_timeout' => 30 * 1000, 19 | 'session' => [ 20 | 'run' => false, 21 | 'kv' => 'test.test.test', 22 | 'ttl' => 3600 * 24 23 | ], 24 | ]; -------------------------------------------------------------------------------- /src/Controller/Test/ExceptionController.php: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | ./tests 18 | 19 | 20 | 21 | 22 | src/ 23 | 24 | 25 | -------------------------------------------------------------------------------- /resource/sql/demo.php: -------------------------------------------------------------------------------- 1 | 'market', 6 | 'insert'=>[ 7 | 'require' => [], 8 | 'limit' => [], 9 | 'sql' => 'INSERT INTO market #INSERT#', 10 | ], 11 | 12 | 'demo_sql_id1_1' => [ 13 | 'table' => "TABLES", 14 | 'sql' => " 15 | SELECT * FROM TABLES 16 | #LIMIT# 17 | ", 18 | ], 19 | 'demo_sql_id1_2_all' => [ 20 | 'sql' => " 21 | SELECT * FROM member_log 22 | WHERE 1 23 | AND `kdt_id` = #{kdt_id} 24 | AND `buyer_id` in #{buyer_id} 25 | #LIMIT# 26 | ", 27 | ], 28 | 'count_sql_id1_2_all' => [ 29 | 'sql' => " 30 | SELECT #COUNT# FROM member_log 31 | WHERE 1 32 | AND `kdt_id` = #{kdt_id} 33 | AND `buyer_id` = #{buyer_id} 34 | ", 35 | ], 36 | 37 | ]; -------------------------------------------------------------------------------- /src/Demo/Service/NovaCall.php: -------------------------------------------------------------------------------- 1 | returnBool()); 17 | $result['Void'] = (yield $service->returnVoid()); 18 | $result['I32'] = (yield $service->returnI32()); 19 | $result['Double'] = (yield $service->returnDouble()); 20 | $result['String'] = (yield $service->returnString()); 21 | $result['Enum'] = (yield $service->returnEnum()); 22 | $result['BaseStruct'] = (yield $service->returnBaseStruct()); 23 | 24 | $result['MixedStruct'] = (yield $service->returnMixedStruct()); 25 | $result['List'] = (yield $service->returnList()); 26 | $result['Set'] = (yield $service->returnSet()); 27 | $result['Map'] = (yield $service->returnMap()); 28 | 29 | 30 | yield $result; 31 | } 32 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2012-2016 Youzan, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /resource/config/online/registry.php: -------------------------------------------------------------------------------- 1 | true, 6 | 7 | // registry 类型 8 | "type" => "etcd", 9 | 10 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 11 | // 服务发现与订阅 12 | 13 | // 服务发现配置 14 | "discovery" => [ 15 | "timeout"=> 3000, 16 | "loop_time" => 1000, //worker定时器任务执行时间(判断是否已拉取到服务) 17 | ], 18 | 19 | //监听服务变更配置 worker#0 20 | "watch" => [ 21 | "timeout" => 30000, // etcd watch 长轮询超时时间 22 | "loop_time" => 5000, //worker定时器任务执行时间(判断执行watch的worker是否live) 23 | ], 24 | 25 | //监听apcu服务列表变更配置 worker#1...n 26 | "watch_store" => [ 27 | "loop_time" => 1000, //worker定时器任务执行时间(判断本地的服务列表是否变化) 28 | ], 29 | 30 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 31 | // 服务拉取 32 | 33 | // 配置从注册中心拉取的服务名称 34 | "app_names" => [ 35 | // "tcp-demo" 36 | ], 37 | 38 | // 配置从注册中心拉取服务的协议(暂时只能是nova)与命名空间(域) 39 | "app_configs" => [ 40 | "tcp-demo" => [ 41 | "protocol" => "nova", 42 | "namespace" => "com.test.service", 43 | ], 44 | ], 45 | 46 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 47 | // 服务发布 48 | 49 | // 发布nova 服务 50 | "novaApi" => [ 51 | 52 | ], 53 | 54 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 55 | // etcd 56 | 57 | // 配置etcd集群节点, 可配置多个 58 | "etcd" => [ 59 | "nodes" => [ 60 | [ 61 | "host" => "127.0.0.1", 62 | "port" => 2379, 63 | ], 64 | ], 65 | ], 66 | 67 | "haunt" => [ 68 | 69 | ], 70 | ]; -------------------------------------------------------------------------------- /resource/config/test/registry.php: -------------------------------------------------------------------------------- 1 | true, 6 | 7 | // registry 类型 8 | "type" => "etcd", 9 | 10 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 11 | // 服务发现与订阅 12 | 13 | // 服务发现配置 14 | "discovery" => [ 15 | "timeout"=> 3000, 16 | "loop_time" => 1000, //worker定时器任务执行时间(判断是否已拉取到服务) 17 | ], 18 | 19 | //监听服务变更配置 worker#0 20 | "watch" => [ 21 | "timeout" => 30000, // etcd watch 长轮询超时时间 22 | "loop_time" => 5000, //worker定时器任务执行时间(判断执行watch的worker是否live) 23 | ], 24 | 25 | //监听apcu服务列表变更配置 worker#1...n 26 | "watch_store" => [ 27 | "loop_time" => 1000, //worker定时器任务执行时间(判断本地的服务列表是否变化) 28 | ], 29 | 30 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 31 | // 服务拉取 32 | 33 | // 配置从注册中心拉取的服务名称 34 | "app_names" => [ 35 | // "tcp-demo" 36 | ], 37 | 38 | // 配置从注册中心拉取服务的协议(暂时只能是nova)与命名空间(域) 39 | "app_configs" => [ 40 | "tcp-demo" => [ 41 | "protocol" => "nova", 42 | "namespace" => "com.test.service", 43 | ], 44 | ], 45 | 46 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 47 | // 服务发布 48 | 49 | // 发布nova 服务 50 | "novaApi" => [ 51 | 52 | ], 53 | 54 | // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 55 | // etcd 56 | 57 | // 配置etcd集群节点, 可配置多个 58 | "etcd" => [ 59 | "nodes" => [ 60 | [ 61 | "host" => "127.0.0.1", 62 | "port" => 2379, 63 | ], 64 | ], 65 | ], 66 | 67 | "haunt" => [ 68 | 69 | ], 70 | ]; 71 | -------------------------------------------------------------------------------- /bin/server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SERVER_BIN=$(dirname $_)/httpd 4 | SERVER_PID=/tmp/ZanHttpDemo.pid 5 | 6 | wait_for_pid () { 7 | try=0 8 | 9 | while test $try -lt 35 ; do 10 | 11 | case "$1" in 12 | 'created') 13 | if [ -f "$2" ] ; then 14 | try='' 15 | break 16 | fi 17 | ;; 18 | 19 | 'removed') 20 | if [ ! -f "$2" ] ; then 21 | try='' 22 | break 23 | fi 24 | ;; 25 | esac 26 | 27 | echo -n . 28 | try=`expr $try + 1` 29 | sleep 1 30 | 31 | done 32 | 33 | } 34 | 35 | case "$1" in 36 | start) 37 | echo -n "Starting server " 38 | 39 | $SERVER_BIN 40 | 41 | if [ "$?" != 0 ] ; then 42 | echo " failed" 43 | exit 1 44 | fi 45 | 46 | wait_for_pid created $SERVER_PID 47 | 48 | if [ -n "$try" ] ; then 49 | echo " failed" 50 | exit 1 51 | else 52 | echo " done" 53 | fi 54 | ;; 55 | 56 | stop) 57 | echo -n "Gracefully shutting down server " 58 | 59 | if [ ! -r $SERVER_PID ] ; then 60 | echo "warning, no pid file found - server is not running ?" 61 | exit 1 62 | fi 63 | 64 | # mac bug 65 | if [ `uname` = "Darwin" ] ; then 66 | kill -TERM `cat $SERVER_PID` 67 | sleep 2 68 | kill -KILL `cat $SERVER_PID` 69 | rm $SERVER_PID 70 | else 71 | kill -TERM `cat $SERVER_PID` 72 | fi 73 | 74 | wait_for_pid removed $SERVER_PID 75 | 76 | if [ -n "$try" ] ; then 77 | echo " failed. " 78 | exit 1 79 | else 80 | echo " done" 81 | fi 82 | ;; 83 | 84 | status) 85 | if [ ! -r $SERVER_PID ] ; then 86 | echo "server is stopped" 87 | exit 0 88 | fi 89 | 90 | PID=`cat $SERVER_PID` 91 | if ps -p $PID | grep -q $PID; then 92 | echo "server (pid $PID) is running..." 93 | else 94 | echo "server dead but pid file exists" 95 | fi 96 | ;; 97 | 98 | restart) 99 | $0 stop 100 | $0 start 101 | ;; 102 | 103 | reload) 104 | 105 | echo -n "Reload server " 106 | 107 | if [ ! -r $SERVER_PID ] ; then 108 | echo "warning, no pid file found - server is not running ?" 109 | exit 1 110 | fi 111 | 112 | kill -USR1 `cat $SERVER_PID` 113 | 114 | echo " done" 115 | ;; 116 | 117 | *) 118 | echo "Usage: $0 {start|stop|restart|reload|status}" 119 | exit 1 120 | ;; 121 | 122 | esac -------------------------------------------------------------------------------- /resource/sql/deamon/mak.php: -------------------------------------------------------------------------------- 1 | 'market', 4 | 'insert'=>[ 5 | 'require' => [], 6 | 'limit' => [], 7 | 'sql' => 'INSERT INTO member_log #INSERT#', 8 | ], 9 | 10 | 'get'=>[ 11 | 'require' => [], 12 | 'limit' => [], 13 | 'sql' => 'select * from member_log where id = 1', 14 | ], 15 | 'batch_insert' => [ 16 | 'require' => [], 17 | 'limit' => [], 18 | 'sql' => 'INSERT INTO member_log #INSERTS#', 19 | ], 20 | 'row_demo_sql_id1_1' => [ 21 | 'sql' => " 22 | SELECT * FROM member_log 23 | WHERE 1 24 | AND `kdt_id` = #{kdt_id} 25 | AND `buyer_id` = #{buyer_id} 26 | #LIMIT# 27 | ", 28 | ], 29 | 'demo_sql_id1_2_all' => [ 30 | 'sql' => " 31 | SELECT * FROM member_log 32 | WHERE 1 33 | AND `kdt_id` = #{kdt_id} 34 | AND `buyer_id` in #{buyer_id} 35 | #LIMIT# 36 | ", 37 | ], 38 | 'count_sql_id1_2_all' => [ 39 | 'sql' => " 40 | SELECT #COUNT# FROM member_log 41 | WHERE 1 42 | AND `kdt_id` = #{kdt_id} 43 | AND `buyer_id` = #{buyer_id} 44 | ", 45 | ], 46 | 'select_sql_id1_2_all' => [ 47 | 'sql' => " 48 | SELECT * FROM member_log 49 | WHERE 1 50 | AND `kdt_id` = #{kdt_id} 51 | AND `buyer_id` = #{buyer_id} 52 | ", 53 | ], 54 | 'select_sql_id1_2_all_aaa' => [ 55 | 'sql' => " 56 | SELECT * FROM member_log 57 | WHERE 1 #WHERE# limit 1 58 | ", 59 | ], 60 | 'update_new_level_id' => [ 61 | 'sql' => " 62 | UPDATE member_log set #DATA#, #AND# 63 | WHERE 1 64 | AND `id` = #{id} 65 | ", 66 | ], 67 | 'select_id' => [ 68 | 'sql' => " 69 | SELECT * FROM member_log 70 | WHERE 1 71 | AND `id` = #{id} 72 | ", 73 | ], 74 | 'row_fans_get' => [ 75 | 'sql' => ' SELECT fans_id,user_id,taobao_user_id,mp_id,fans_weixin_openid,fans_nickname,`comment` FROM fans 76 | WHERE 1 77 | AND `fans_id` = #{fans_id}', 78 | ] 79 | ]; -------------------------------------------------------------------------------- /src/Controller/Index/IndexController.php: -------------------------------------------------------------------------------- 1 | display("Demo/welcome/welcome"); 20 | } 21 | 22 | public function exception() 23 | { 24 | throw new \Exception("service unavailable", 503); 25 | } 26 | 27 | //json输出示例 28 | public function json() 29 | { 30 | yield $this->r(0, 'json string', ["Hello" => "World"]); 31 | } 32 | 33 | //模板输出示例 34 | public function showTpl() 35 | { 36 | //给模板中的变量赋值 37 | $this->assign("str", "Zan Framework"); 38 | //输出模板页面 39 | yield $this->display("Demo/test/test"); 40 | } 41 | 42 | //操作数据库示例 43 | public function dbOperation() 44 | { 45 | $demo = new GetDBData(); 46 | //执行sql语句 47 | $result = (yield $demo->doSql()); 48 | yield $this->r(0, 'json string', $result); 49 | } 50 | 51 | public function redisOperation() 52 | { 53 | $demo = new GetCacheData(); 54 | 55 | //执行Redis命令 56 | $result = (yield $demo->doCacheCmd()); 57 | yield $this->r(0, 'json string', $result); 58 | } 59 | 60 | //Http服务调用示例 61 | public function httpRemoteService() 62 | { 63 | $http = new HttpCall(); 64 | $resp = (yield $http->visit()); 65 | 66 | $resp = new Response($resp->getBody()); 67 | $resp->withHeaders(['Content-Type' => 'text/javascript;charset=utf-8']); 68 | 69 | yield $resp; 70 | } 71 | 72 | // 调用 远程NOVA 服务 73 | public function novaRemoteService() 74 | { 75 | try { 76 | $tcp = new NovaCall(); 77 | $result = (yield $tcp->invokeRemoteNovaMethod()); 78 | yield $this->r(0, 'json string', $result); 79 | } catch (\Exception $e) { 80 | $msg = get_class($e) . ":" . $e->getMessage(); 81 | sys_error($msg); 82 | yield $this->r(0, $msg, null); 83 | } 84 | } 85 | 86 | public function testSession() 87 | { 88 | /** @var Session $session */ 89 | $session = (yield getSessionHandler()); 90 | yield $session->set("hello", "world"); 91 | 92 | yield $this->display("Demo/welcome/welcome"); 93 | } 94 | } --------------------------------------------------------------------------------