du3932066 2012-07-25 17:41
浏览 142

PHP,AJAX:大数据被截断

The Problem

I'm using jQuery to post a (relatively) large amount of data to a web system I am migrating from Ubuntu to CentOS (a painful process). The problem is that the data being received is truncated. Sending the same data from the server to the client results in no truncation.

The amount of data being 'sent' (that is, what I'm seeing while debugging Javascript) is 116,902 bytes (the correct amount of data), whereas the amount of data being received is approximately 115,668 bytes: this number seems to vary, making me believe the problem may be time related. The transaction completes (receive, response) in approximately 3.1 seconds, not a huge amount of time. Are there any settings I should examine?

That idea aside, my PHP installation is configured to accept 8M of post data and use to 128M of physical memory, which seems plenty enough.

The jQuery code is below. I'm quite sure this isn't the problem, but I've included it as requested.

Receiving:

function synchronise_down()
{
    $.ajax({url: "scripts/get_data.php",
        context: document.body,
        dataType: "json",
        type: "POST",
        success: function(result)
            {
                // Fix the state up.
                update_data(result);

                // Execute on syncronise.
                execute_on_synchronise();
            },
        error: function(what, huh)
            {
                IS_WAITING = false;
            }
        });
}

Sending:

function synchronise_up()
{
    var serialised = MIRM_MODEL.serialise();
    LAST_SERIALISED = new Date().getTime();
    $.ajax({url: "scripts/save_model.php",
        context: document.body,
        dataType: "json",
        data: {"model":serialised},
        type: "POST",
        success: function(result)
            {
                // Fix the state up.
                update_data(result, true);

                // Execute on syncronise.
                execute_on_synchronise();
            },
        error: function(what, huh)
            {
                IS_WAITING = false;
            }
        });
}

Workaround (Wouldn't call this a solution)

Edit: I've 'fixed' this, but not necessarily found out what the problem is and how to solve it. It's an interesting problem so I'll describe my workaround and leave the question open.

What I'm doing is rather than letting jquery handle the serialisation of my large data, I'm doing it myself first, essentially serialising twice. the code for this is as follows:

function synchronise_up()
{
    var serialised = JSON.stringify(MIRM_MODEL.serialise());
    LAST_SERIALISED = new Date().getTime();
    $.ajax({url: "scripts/save_model.php",
        context: document.body,
        dataType: "json",
        data: {"model":serialised},
        type: "POST",
        success: function(result)
            {
                // Fix the state up.
                update_data(result, true);

                // Execute on syncronise.
                execute_on_synchronise();
            },
        error: function(what, huh)
            {
                IS_WAITING = false;
            }
        });
}

The important line is of course:

var serialised = JSON.stringify(MIRM_MODEL.serialise());

Now, when it hits the server, I need to decode this data because it's been serialised twice. There are added costs with this 'solution': sending more data, doing more work. The question still remains: what's the problem, and what's the real solution?

  • 写回答

4条回答 默认 最新

  • dongyun6229 2012-07-25 23:23
    关注

    Try setting jQuery's ajax timeout parameter to a high number (note, it's in milliseconds, so you'll probably want 10000 which is 10 seconds). Some other options to try: 1. Check that your PHP max execution time is a decent amount. I doubt this would be related but it's possible. 2. On jQuery's error function, run console.log(xhr) on the XHR result (you'd have to do this in Chrome or find another method of seeing the result). XHR is an XHR object that contains debug information on what happened with the connection e.g. Status codes, timeout info, etc.

    EDIT: Also, have you checked the max size of the field in your Database? It's quite possible that the Database is automatically truncating the information.

    评论

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿