php.ini
- post_max_size
- upload_max_filesize
nginx.conf
- client_max_body_size
php.ini
nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
try{ static $instances; if(!isset($instances)){ $dbLink = new StatDBLink( $this->options['db_host'], $this->options['db_user'], $this->options['db_pwd'] ); $dbo = new StatDbo($dbLink); $dbo->isDebug = $this->isDebug(); $tools = new StatTools($dbo); $ip = new StatIpLocation(__DIR__ . '/QQWry.Dat'); $region = new StatArea(); $instances = new StatLog($tools, $ip, $region); } $this->isDebug() && $this->log(var_export($data, true)); $instances->add($data); } catch(Exception $e){ $this->log($e->getMessage()); $this->logError($e->getMessage()); // 清理资源,在swoole下特别注意,经常unset()不需要的变量 unset($instances); if(isset($dbLink)){ $dbLink->close(); unset($dbLink); } } |
在发生Exception后,static类型的变量instances未被unset
这一年又这样过了,这几天一直在准备,感觉不知从何开始,与往常一样,就这样平淡的度过了一年
这一年比较好的是有很多时间专门写代码的时间,进来个产品帮我做了大部分不是技术开发做的事,少了很多无效率的会议,产品设计等工作, 在技术上:
在工作上:
学习了以下书籍(部分书籍粗浅的、片断阅读):
在生活上:严重不及格,很多计划都未实现
https://pdepend.org/documentation/what-is-php-depend.html
https://github.com/sebastianbergmann/phploc
https://phpmd.org/about.html
https://github.com/sebastianbergmann/phpcpd
statis配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "type": "package", "package" : { "name": "symfony/process", "version": "3.2.0", "dist": { "url": "https://github.com/symfony/process/archive/v3.2.0.zip", "type" : "zip" }, "require": { "php": ">=5.5.9" }, "autoload": { "psr-4": { "Symfony\\Component\\Process\\": "" }, "exclude-from-classmap": [ "/Tests/" ] } } }, |
由于之前未定义require, autoload配置项,导致安装后无法安装相关依赖及配置psr4映射
参考:
http://docs.phpcomposer.com/faqs/why-can%27t-composer-load-repositories-recursively.html
statis配置
1 2 3 |
{ "require-dependencies": true } |
登录252服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
cd /data/git/satis vim satis.json { "name": "Jz's Repository", "homepage": "http://packages.9z.cn", "repositories": [ {"type": "vcs", "url": "https://github.com/composer/composer"}, {"type": "vcs", "url": "https://github.com/php-fig/log"}, {"type": "vcs", "url": "https://github.com/symfony/debug"}, {"type": "vcs", "url": "https://github.com/symfony/polyfill-mbstring"}, {"type": "vcs", "url": "https://github.com/symfony/console"}, {"type": "vcs", "url": "git@test:repos/j.git"}, {"type": "vcs", "url": "git@test:repos/j-core.git"}, {"type": "vcs", "url": "git@test:repos/j-console.git"}, {"type": "vcs", "url": "git@test:repos/j-db.git"}, {"type": "vcs", "url": "git@test:repos/j-tree.git"}, {"type": "vcs", "url": "git@test:repos/j-region.git"}, {"type": "vcs", "url": "git@test:repos/j-spider.git"}, {"type": "vcs", "url": "git@test:repos/j-wxsdk.git"}, {"type": "vcs", "url": "git@test:repos/j-segmentation.git"}, {"type": "vcs", "url": "git@test:repos/j-log.git"}, {"type": "vcs", "url": "git@test:repos/j-payment.git"}, {"type": "vcs", "url": "git@test:repos/j-project.git"}, {"type": "vcs", "url": "git@test:repos/ide-doc.git"}, {"type": "vcs", "url": "git@test:repos/j-tcp.git"}, {"type": "vcs", "url": "git@test:repos/j-http.git"}, {"type": "vcs", "url": "git@test:repos/j-http1.git"}, {"type": "vcs", "url": "git@test:repos/syar.git"}, {"type": "vcs", "url": "git@test:repos/j-api.git"} ], "require-all": true, "archive": { "directory": "dist", "format": "tar" } } |
可以下载一些常用的开源包缓存到公司
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "type": "package", "package" : { "name": "composer/composer", "version": "1.2.3", "dist": { "url": "https://github.com/composer/composer/archive/1.2.3.zip", "type" : "zip" } } }, { "type": "package", "package" : { "name": "psr/log", "version": "1.0.2", "dist": { "url": "https://github.com/php-fig/log/archive/1.0.2.zip", "type" : "zip" } } }, |
生成静态资源包
1 |
php bin/satis build satis.json www/ [packname] |
生成过程中如果需要输入Token, 访问提示的地址, 在github生产新token即可
配置nginx
1 2 3 4 5 6 7 |
server { listen 80; server_name packages.9z.cn; root /data/git/satis/www; index index.html; charset utf-8; } |
1 |
composer config -g secure-http false |
1 2 3 4 5 6 7 8 9 10 11 |
"repositories": [ { "type": "composer", "url": "http://packages.9z.cn" }, { "type": "composer", "url": "https://packagist.phpcomposer.com" }, {"packagist": false} ], |
1 |
composer require LIB_NAME |
安装项目
1 2 3 |
cd your_path composer create-project --repository-url http://packages.9z.cn/ stcer/j-project YOUR_PROJECT_DIR dev-master composer create-project --no-dev --repository-url http://packages.9z.cn/ stcer/j-project project3 dev-master |
1 |
composer require stcer/syar |
测试脚本 example/benchmark.php, 测试环境(虚拟机)
脚本一共完成44次接口调用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
function test($type, $times = 5, $limit = 5){ $timer = new Timer(); $benchmark = new Benchmark($type); $rs[] = $benchmark->simpleTest(); // 2 $rs[] = $benchmark->dbTest($limit); // 2 $rs[] = $benchmark->batchTest($times, $limit); // 20 $rs[] = $benchmark->concurrentTest($times, $limit); // 20 $stop = $timer->stop(); // 44 calls, 22 db, 22 normal foreach($rs as $v){ var_dump($v); } return $stop; } // start test $times['syar'] = test('syar'); $times['fpm'] = test('fpm'); var_dump($times); --------------------------- output: array(2) { ["syar"]=> float(0.01271) ["fpm"]=> float(0.08602) } |
在当前测试环境下,fpm环境下的执行时间大概是syar下的4 — 6倍左右, 稍后做更详细的压力测试,服务器、客户端资源占用情况测试
github:https://github.com/stcer/syar
注册加载器, 对象创建工厂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class RuntimeLoader implements Twig_RuntimeLoaderInterface { public function load($class) { // implement the logic to create an instance of $class // and inject its dependencies // most of the time, it means using your dependency injection container if ('Project_Twig_RuntimeExtension' === $class) { return new $class(new Rot13Provider()); } else { // ... } } } $twig->addRuntimeLoader(new RuntimeLoader()); |
定义扩展
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
class Project_Twig_RuntimeExtension extends Twig_Extension { private $rot13Provider; public function __construct($rot13Provider) { $this->rot13Provider = $rot13Provider; } public function rot13($value) { return $rot13Provider->rot13($value); } } class Project_Twig_Extension extends Twig_Extension { public function getFunctions() { return array( new Twig_SimpleFunction('rot13', array('Project_Twig_RuntimeExtension', 'rot13')), // or new Twig_SimpleFunction('rot13', 'Project_Twig_RuntimeExtension::rot13'), ); } } |
了解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
"require": { "stcer/demo" : "*", "stcer/j" : "0.1.0" }, "repositories": [ { "type": "path", "url": "../stcer-demo", "options": { "symlink": false } }, { "type": "vcs", "url": "git@192.168.0.252:repos/j.git" } ], |
task中能返回的数据通过php的Serialization函数返回到worker进程,因此像Closure等不能被序列化的对象不能返回,包括$exception中可能包括Closure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function onTask($serv, $task_id, $from_id, $data){ if(!is_array($data) || !$data['id']){ return new Exception("Invalid task data"); } $id = $data['id']; if(!isset($this->callbacks[$id])){ return new Exception("Invalid task id"); } try{ $callback = $this->callbacks[$id][0]; $rs = call_user_func_array($callback, $data['data']); return $rs; } catch(Exception $e){ return $e; // 可能出错,使work进程不能正常运行 } } |