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

关于 php-cli 运行模式的问题

  •  
  •   linbomb · Oct 27, 2015 · 5140 views
    This topic created in 3838 days ago, the information mentioned may be changed or developed.

    现在有一个场景需要不断调用某个接口去统计一批数据,在 php-cli 模式下请求 10w 多次接口以后速度开始下降,后来就不动了。干掉进程重新统计没多少次有停住了。接口没有任何限制。
    后来换了台机器,也是跑了 10w 多次之后变慢停住。
    哪位高手帮忙解答下是哪里出了问题?

    9 replies    2015-10-27 22:46:47 +08:00
    mahone3297
        1
    mahone3297  
       Oct 27, 2015
    我猜是内存的问题
    写 shell 去调 php-cli
    linbomb
        2
    linbomb  
    OP
       Oct 27, 2015
    @mahone3297 额。。这个不太明白,能简单说下吗
    cevincheung
        3
    cevincheung  
       Oct 27, 2015 via Android
    curl multi
    moro
        4
    moro  
       Oct 27, 2015
    看 php 日志。
    aliang032
        5
    aliang032  
       Oct 27, 2015   ❤️ 1
    估计是短链接,没开端口复用,本地端口被耗光了。
    解决方法:

    vi /etc/sysctl.conf

    追加
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_timestamps = 1

    保存后运行
    sysctl -p
    bin20060407
        6
    bin20060407  
       Oct 27, 2015
    错误级别开启到最大,检查日志。估摸是内存泄漏,长时间驻守后台进程,该 close 的 close ,该 unset 的 unset 。
    mahone3297
        7
    mahone3297  
       Oct 27, 2015
    @linbomb 我的意思,就是写个 shell 脚本,去执行你的 php 代码。
    比如
    test.sh
    ```shell
    php test.php
    ```
    rming
        8
    rming  
       Oct 27, 2015
    让我不禁想问 supervisor 是怎么处理的,查了下文档,好像没看明白 僵死 是什么状态

    http://supervisord.org/subprocess.html
    fuxkcsdn
        9
    fuxkcsdn  
       Oct 27, 2015 via iPhone
    肯定是没合理利用 cURL_multi 和 http 长连接,我工作需要写的调用供应商接口的 cURL_multi 封装类每半小时执行 20W 次请求都没任何问题(然后供应商服务器撑不住就停了我们账号...)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1334 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 17:03 · PVG 01:03 · LAX 10:03 · JFK 13:03
    ♥ Do have faith in what you're doing.