Swoole HTTP server to implement the Jump function, and the program can not continue to execute down

Source: Internet
Author: User
Use the Swoole_http_response method header,status,end to implement a jump

The code is as follows

  public function redirect($url)    {        $this->header("Location", $url);        $this->status(302);        return $this->end('');    }

But after using redirect (), the program is not interrupted, or continues to execute,

Then I broke the program with an exception and didn't let him go back, but this method caused the worker to restart,

question: There is no good way, after the page jump, the program immediately interrupted, will not continue to execute, the page immediately jump? Requires a method that does not use throwing exceptions to interrupt the program

Reply content:

Use the Swoole_http_response method header,status,end to implement a jump

The code is as follows

  public function redirect($url)    {        $this->header("Location", $url);        $this->status(302);        return $this->end('');    }

But after using redirect (), the program is not interrupted, or continues to execute,

Then I broke the program with an exception and didn't let him go back, but this method caused the worker to restart,

question: There is no good way, after the page jump, the program immediately interrupted, will not continue to execute, the page immediately jump? Requires a method that does not use throwing exceptions to interrupt the program

I was going to say exit (0), it feels a little wrong.

Didn't use Swoole, just looked at the Swoole document,

Swoole_http_response->end
Sends the HTTP response body and ends the request processing.
Swoole_http_response->end (string $html);
The end action sends HTML content to the client browser and destroys the $request/$response object
If KeepAlive is turned on, the connection will remain and the server will wait for the next request
If KeepAlive is not turned on, the server will disconnect

End () After the $response object is destroyed, the HTTP response is complete, and the business code should not be executed.

Http://wiki.swoole.com/wiki/p ...
Can be understood as reactor is Nginx,worker is PHP-FPM. The reactor thread asynchronously processes the network request in parallel and then forwards it to the >worker process to process it. Communication between the reactor and the worker through the IPC method.

Swoole Reactor,worker,task_worker can be tightly combined to provide a more advanced way of use.

A more popular metaphor, assuming that the server is a factory, that reactor is sales, to help you get the project order. The worker is the worker, when sells > sells the order, the worker goes to work to produce the customer wants the thing. And Task_worker can be understood as the administrative staff, can help the worker to do some miscellaneous >, let the worker concentrate on work.

Woker reboot doesn't seem to have any effect.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.