PHP script runs successfully but no response

WBOY
Release: 2016-08-04 09:20:58
Original
2074 people have browsed it

There is a function developed with the TP3.1 framework. After the calculation is completed, it is required to return {"status":0}
The final code is

<code> 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);</code>
Copy after login
Copy after login

The running result is

<code>[ 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</code>
Copy after login
Copy after login

But the page does not have echo json_encode($data);
F12 check the http request and there is no return, but the calculation is completed, the code is basically pasted, as long as you delete some of the code that takes a long time to calculate, you can get the return value, but I have set max_execution_time, and the calculation did not exceed the time
PHP script runs successfully but no response
PHP script runs successfully but no response

Reply content:

There is a function developed with the TP3.1 framework. After the calculation is completed, it is required to return {"status":0}
The final code is

<code> 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);</code>
Copy after login
Copy after login

The running result is

<code>[ 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</code>
Copy after login
Copy after login

But the page does not have echo json_encode($data);
F12 check the http request and there is no return, but the calculation is completed, the code is basically pasted, as long as you delete some of the code that takes a long time to calculate, you can get the return value, but I have set max_execution_time, and the calculation did not exceed the time
PHP script runs successfully but no response
PHP script runs successfully but no response

<code class="php">
 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;//退出脚本
</code>
Copy after login

$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);

Try it like this and see if it runs here

Made ajax request? Browser F12 to see if the requested link was successful and if a reply was received. The information given is too little, please provide more details.


I don’t see any obvious problem. Is the timeout set for the request made using xhr? The return value is ignored because the calculation takes too long. By the way, it is recommended to add header('Content-Type: application/json');

before echo json
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template