我在阿里云code建了一个私有git项目,阿里云code支持webhook,我用workerman来实现的。但是workerman获取的阿里云code的POST数据总是格式不对:
array(1) {
=>
array(1) {
["{"id":"5a3b34c5597e9ea857fc122f373dcbaba3852","message":"ADD: testing git webhook\n","timestamp":"2016-06-23T22:45:33 08:00","url":"https://code.aliyun.com/taoqu/service/commit/5a3b34c5597ec1a857fc122f373dcbaba3852","author":{"name":"henry","email":"chary@gmail.com"},"added":=>
string(0) ""
}
}
造成json_decode无法解析。
在httpd环境下用 php://input 读取的实际数据为:
{"object_kind":"push","before":"530aa7d005f43f54c69a885988e806653","after":"26a1e301809b34b1c1ba942e1412ec46","ref":"refs/heads/master","checkout_sha":"26a1e87870b34b1c1ba942e1412ec46","message":null,"user_id":11066,"crp_user_identity":"1896030318257386","user_name":"chary","user_email":"chary@163.com","project_id":16569,"repository":{"name":"website","url":"git@code.aliyun.com:taoq/website.git","description":"网站","homepage":"https://code.aliyun.com/taoq/website","git_http_url":"https://code.aliyun.com/taoq/website.git","git_ssh_url":"git@code.aliyun.com:tao/website.git","visibility_level":0},"commits":[{"id":"26a1e87870301809f18b3942e1412ec46","message":"Merge branch 'dev'\n","timestamp":"2016-09-28T09:24:00+08:00","url":"https://code.aliyun.com/taoqu/website/commit/26a1e878703018018b34b1c1ba942e1412ec46","author":{"name":"henry","email":"chariy@163.com"},"added":[],"modified":,"removed":[]},{"id":"557eeec796fa990097262097b0da43f854","message":"修复商品类层级大于3时,搜索引擎失败的问题\n","timestamp":"2016-09-28T09:19:45+08:00","url":"https://code.aliyun.com/taoqu/website/commit/557eeec796fa99009a1cae17262097b0da43f854","author":{"name":"henry","email":"chariy@163.com"},"added":[],"modified":,"removed":[]},{"id":"530aa7d005f43f54c6bf76988e806653","message":"Merge branch 'dev'\n","timestamp":"2016-09-27T18:03:21+08:00","url":"https://code.aliyun.com/taoq/website/commit/530aa7d005f43f54c6bf50f769a885988e806653","author":{"name":"hry","email":"chary@163.com"},"added":[],"modified":,"removed":[]}],"total_commits_count":3}
这个数据是标准的json数据,是可以被json_decode成功解析的。
遗憾的是workerman读取php://input得出的是空字符串。
请问是workerman原来就这样设计的?还是我使用上有问题?
php://input在php-fpm或者apache下才有效。php cli下无效。
这个不是workerman的限制,是PHP cli的限制。
如果是workerman下的http协议,用 $GLOBALS 来代替 php://input