PHP指令碼運行成功,卻無反應

來源:互聯網
上載者:User

有個以TP3.1架構開發的功能,計算完成後要求返回{"status":0}
代碼最後為

 ini_set("max_execution_time", "800");   ... $data['status'] = 0; Log::write(json_encode($data),Log::DEBUG); echo json_encode($data); Log::write('echo success',Log::DEBUG);

運行結果為

[ 2016-07-18T14:50:36+08:00 ] DEBUG: 已耗用時間:486.8268s[ 2016-07-18T14:50:36+08:00 ] DEBUG: {"status":0}[ 2016-07-18T14:50:36+08:00 ] DEBUG: echo success

但是頁面沒 echo json_encode($data);
F12查看http請求就一直沒有返回,但是計算卻運行完成了,代碼基本都貼全了,只要刪除一部分計算時間長的代碼,就可以得到傳回值,但是我已經設定了max_execution_time,計算也沒超過時間

回複內容:

有個以TP3.1架構開發的功能,計算完成後要求返回{"status":0}
代碼最後為

 ini_set("max_execution_time", "800");   ... $data['status'] = 0; Log::write(json_encode($data),Log::DEBUG); echo json_encode($data); Log::write('echo success',Log::DEBUG);

運行結果為

[ 2016-07-18T14:50:36+08:00 ] DEBUG: 已耗用時間:486.8268s[ 2016-07-18T14:50:36+08:00 ] DEBUG: {"status":0}[ 2016-07-18T14:50:36+08:00 ] DEBUG: echo success

但是頁面沒 echo json_encode($data);
F12查看http請求就一直沒有返回,但是計算卻運行完成了,代碼基本都貼全了,只要刪除一部分計算時間長的代碼,就可以得到傳回值,但是我已經設定了max_execution_time,計算也沒超過時間

 ini_set("max_execution_time", "800");   ... $data['status'] = 0; Log::write(json_encode($data),Log::DEBUG); echo json_encode($data); Log::write('echo success',Log::DEBUG); exit;//退出指令碼

$data['status'] = 0;
echo 1;
Log::write(json_encode($data),Log::DEBUG);
echo 2;
echo json_encode($data);
echo 3;
Log::write('echo success',Log::DEBUG);

這樣試試 看運行到這裡沒

做的ajax請求?瀏覽器F12看看請求的連結有沒有成功,有沒有收到回複。給的資訊太少了,補充詳細一點。

看不出什麼明顯的問題,用的xhr做的請求,是不是設定了timeout?導致計算時間過長就忽略傳回值了。順便,建議在echo json前加上header('Content-Type: application/json');

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.