yadgen
V2EX  ›  PHP

laravel 优化

By yadgen at 2017 年 10 月 19 日 · 6529 次点击
laravel 框架默认输出 hello world 需要几十毫秒,优化到只有几毫秒,有什么思路?
24 条回复  •  2017-10-20 16:21:08 +08:00
Magician
   1
Magician  
   2017 年 10 月 19 日 via iPhone   ❤️ 1
echo 0.000000000001 微秒 自我催眠
takanasi
   2
takanasi  
   2017 年 10 月 19 日 via Android
不用框架?
2ME
   3
2ME  
   2017 年 10 月 19 日
关闭 session 试试?
thomasjiao
   4
thomasjiao  
   2017 年 10 月 19 日
关闭所有 middleware 和 service provider ;
路由缓存,配置缓存;
silencefent
   5
silencefent  
   2017 年 10 月 19 日
/index.php

echo "hello world"
lbp0200
   6
lbp0200  
   2017 年 10 月 19 日
没什么意义
FishInShallow
   7
FishInShallow  
   2017 年 10 月 19 日
不用它的模板引擎试试
z21victor
   8
z21victor  
   2017 年 10 月 19 日
这个是图啥,如果只输出,就不用框架呗
b821025551b
   9
b821025551b  
   2017 年 10 月 19 日
毫无意义
wdlth
   10
wdlth  
   2017 年 10 月 19 日 via Android
难道用框架是为了输出 Hello World ?不用写业务逻辑?
HYSS
   11
HYSS  
   2017 年 10 月 19 日
不可能的 就算仅仅留下个 Kernel 还是会几十
yadgen
   12
yadgen  
OP
   2017 年 10 月 19 日
@thomasjiao 没用,试过了。
yadgen
   13
yadgen  
OP
   2017 年 10 月 19 日
@HYSS 试试 kernel 内存常驻呢?
TypeErrorNone
   14
TypeErrorNone  
   2017 年 10 月 19 日
还是把重点放到 mysql 上,php 这块到时开启 opcache 就行了,laravel 可以用 lumen 代替
yadgen
   15
yadgen  
OP
   2017 年 10 月 19 日
@TypeErrorNone mysql 也简单,减少 IO,redis or memcache, 减少请求,在上游优化等等手段。
dryyun
   16
dryyun  
   2017 年 10 月 19 日
换个轻量级框架 ?
pqee
   17
pqee  
   2017 年 10 月 19 日
14 年的 Laravel 4.2 默认配置 hello world 要 150 ms,该满足了。

如果你实在是想优化性能,换 PHP 效果最好。
pqee
   18
pqee  
   2017 年 10 月 19 日
补充:换 PHP7 效果最好
gouchaoer
   19
gouchaoer  
   2017 年 10 月 19 日 via Android
opcache,session 存 redis/memcache,php7,没了
allenhu
   20
allenhu  
   2017 年 10 月 19 日 via Android
lumen 试试?
jfcherng
   21
jfcherng  
   2017 年 10 月 19 日
還有 composer dump-autoload -o
jswh
   22
jswh  
   2017 年 10 月 20 日
我猜你没开 opcache,之前也是。开了 opcache 之后框架启动时间就只有几到十几毫秒了
goodspb
   23
goodspb  
   2017 年 10 月 20 日
有个不错的思路,将框架常驻在内存,每次只是执行逻辑部分。
PS: 不过这个坑很多,公司用 laravel4.2 就这样跑过,稳定性稍差。

现成可参考的轮子有:

https://github.com/scil/LaravelFly
https://github.com/chongyi/swoole-laravel-framework
https://github.com/garveen/laravoole
songhuasahn
   24
songhuasahn  
   2017 年 10 月 20 日
原生好了
© 2026 V2EX · 92ms · 3.9.8.5