V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yadgen
V2EX  ›  PHP

laravel 优化

  •  
  •   yadgen · Oct 19, 2017 · 6056 views
    This topic created in 3124 days ago, the information mentioned may be changed or developed.
    laravel 框架默认输出 hello world 需要几十毫秒,优化到只有几毫秒,有什么思路?
    24 replies    2017-10-20 16:21:08 +08:00
    Magician
        1
    Magician  
       Oct 19, 2017 via iPhone   ❤️ 1
    echo 0.000000000001 微秒 自我催眠
    takanasi
        2
    takanasi  
       Oct 19, 2017 via Android
    不用框架?
    2ME
        3
    2ME  
       Oct 19, 2017
    关闭 session 试试?
    thomasjiao
        4
    thomasjiao  
       Oct 19, 2017
    关闭所有 middleware 和 service provider ;
    路由缓存,配置缓存;
    silencefent
        5
    silencefent  
       Oct 19, 2017
    /index.php

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

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

    现成可参考的轮子有:

    https://github.com/scil/LaravelFly
    https://github.com/chongyi/swoole-laravel-framework
    https://github.com/garveen/laravoole
    songhuasahn
        24
    songhuasahn  
       Oct 20, 2017
    原生好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5810 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 103ms · UTC 06:25 · PVG 14:25 · LAX 23:25 · JFK 02:25
    ♥ Do have faith in what you're doing.