dqzve68846 2017-09-29 09:08
浏览 47

MySQL服务器重载了PDO请求 - 如何防范?

I got a PHP script which browses files containing infos about 1M or 2M users Some users need to be updated due to changes provided.

I must be very naive, but thought my sequential code would send request after request, and couldn't overload the servers. The fact is : I put the 4 cpus of a production server to 95% use at my first run, and had a cron crash tonight, on another server.

So I guess PDO requests are sent to the server, and asynchronously executed. Nice, but... how can I avoid to overload it then ? I couldn't find anything on the topic, so I guess I'm not looking for the right keywords.

My code logic is pretty simple :
For every user, I send first a SELECT request to check if the UPDATE is necessary, and if it is, I actually execute the UPDATE request.
I wonder why, but checking with the first SELECT request proved more efficient than just "updating 0 lines" with the same WHERE restrictions

The code can be roughly summed-up as this :

foreach ($parsed_user as $user => $infos) {
    //PDO value bindings
    if ($stmt_check_user_need_update->execute()){
        continue;

    if ($stmt_update->execute()) {
        //log success
    }
    else {
        //log error
}

As long as it doesn't crash, this works pretty well. The thing is... I'd like it to be reliable, and avoid impacting production environments.

I run updates on both SQL-Server and MySQL.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多
    • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
    • ¥30 ppOCRLabel导出识别结果失败