XHProf 是 Facebook 开源出来的一个php轻量级的性能分析工具,跟Xdebug 类似,但性能开销更低,还可以用在生产环境中,也可以由程序开关来控制是否进行 profile。
最近发现 Laravel 在处理某类队列任务时时间超长,经排查发现 src/Illuminate/Queue/Jobs/Job.php 文件中的 rolveQueueableEntity 使用了 Illuminate Str 的 startsWith,此方法中使用了 mb_strpos 方法。mb_strpos 的性能非常差1,在处理大 string (100M以上) 时会产生严重性能问题。可以看到这里处理的数据有一种是序列化后的 Job 实例,是有可能出现大的 string.
Elasticquent 是与 Larave Model Eloquent 结合的 Elasticsearch 客户端,它可以轻松的将 Eloquent 中定义好的数据和关系映射并同步到 Elasticsearch 中。
在做后台权限系统的时候需要将所有在框架中注册的 Router Names 同步到数据库中以便后台配置权限,可以使用 Laravel 中全局变量 $app 中获取到相关信息:
global $app; //Illuminate\Routing\Router Object $routers = $app['router']; //Illuminate\Routing\RouteCollection Object $router_collection = $routers->getRoutes();
取出 Route Collection 后就可以遍历取出 Illuminate Routing Route 对象,读出需要的信息。比如:
$router->domain(); $router->getName();
2014 年的最后一天,写个小问题,没有答案。
A, B 两地,A 开往 B 的列车每整点发车,10 小时到达;B 开往 A 的列车,每半点发车,12 小时到达。那么问题来了,A 出发的列车到达 B 时迎面会遇到多少辆从 B 驶向 A 的列车。 限时 3 分钟。
Returns the number X, truncated to D decimal places. If D is 0, the result has no decimal point or fractional part. D can be negative to cause D digits left of the decimal point of the value X to become zero.