Swoolehttpserver implements the jump function, and the program can not continue to execute

Source: Internet
Author: User
Use the swoole_http_response method header, status, and end to redirect the code as follows {code ...} however, after redirect () is used, the program is not interrupted and continues to be executed. later, I throw an exception to interrupt the program and won't let him continue executing it later. However, this... use the swoole_http_response method header, status, and end to redirect

The code is as follows:

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

However, after redirect () is used, the program is not interrupted and continues to be executed,

Later, I used an Exception thrown to interrupt the program and prevent him from executing it later. However, this method causes worker to restart,

Problem:Is there a good way to do this? after a page jump, the program will be interrupted immediately and it will not continue to be executed. Will the page jump immediately? Do not use methods that throw exceptions to interrupt the program

Reply content:

Use the swoole_http_response method header, status, and end to redirect

The code is as follows:

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

However, after redirect () is used, the program is not interrupted and continues to be executed,

Later, I used an Exception thrown to interrupt the program and prevent him from executing it later. However, this method causes worker to restart,

Problem:Is there a good way to do this? after a page jump, the program will be interrupted immediately and it will not continue to be executed. Will the page jump immediately? Do not use methods that throw exceptions to interrupt the program

I would like to say that exit (0) is a bit wrong.

Swoole has never been used. I read swoole's document just now,

Swoole_http_response-> end
Send the Http response body and end request processing.
Swoole_http_response-> end (string $ html );
After the end operation, the system sends HTML content to the client browser and destroys the $ request/$ response object.
If KeepAlive is enabled, the connection is retained, and the server waits for the next request.
KeepAlive is not enabled, and the server will disconnect

$ Response object is destroyed after end (). the http response is complete and the business code will not be executed.

Http://wiki.swoole.com/wiki/p...
It can be understood that the reactor is nginx, and the worker is php-fpm. The reactor thread processes network requests asynchronously and concurrently, and then forwards the requests to> worker processes for processing. Reactor and worker communicate with each other through IPC.

Swoole's reactor, worker, and task_worker can be closely integrated to provide more advanced usage methods.

In a more common analogy, assume that the Server is a factory, and the reactor is sales, helping you pick up project orders. While worker is a worker. after sales and sales are received, worker will work to produce what the customer wants. Task_worker can be understood as an administrative staff who can help the worker to do more complex tasks, so that the worker can concentrate on its work.

It seems that the woker restart has no effect.

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.