yadgen
V2EX  ›  PHP

laravel 优化

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

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

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

    现成可参考的轮子有:

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