How does PHP handle HTTPS requests?

Source: Internet
Author: User
How can I use PHP to process HTTPS requests? What I want to ask is not to use curl to send a request, nor to ask about the principle of https. I just want to know what configuration or code PHP needs to write to process the request after the browser sends an HTTPS request, can you have sample code? I searched the internet, but it wasn't curl... How can I use PHP to process HTTPS requests?
What I want to ask is not to use curl to send a request, nor to ask about the principle of https. I just want to know what configuration or code PHP needs to write to process the request after the browser sends an HTTPS request, can you have sample code?
I have searched the internet. It's not an example of curl sending https requests, but an example of HTTPS principles. But I understand the principles, but I don't know how to start...
Thank you.

Reply content:

How can I use PHP to process HTTPS requests?
What I want to ask is not to use curl to send a request, nor to ask about the principle of https. I just want to know what configuration or code PHP needs to write to process the request after the browser sends an HTTPS request, can you have sample code?
I have searched the internet. It's not an example of curl sending https requests, but an example of HTTPS principles. But I understand the principles, but I don't know how to start...
Thank you.

phpAndhttpsPhp is a language/script interpreter, not a server.

A request arrives at the server, whether it ishttpOrhttps, First pass throughweb server, Suchapache,nginx,web serverBetween processing and clienthttp/httpsProtocol Data Interaction

Determine whether to call according to certain rules (such as extensions)phpTo process this request, there are many calling methods, suchModuleMethod,CGIMethod and CGI-basedfastcgi/fpmMethod, depending onweb serverConfiguration

After the call,phpSpit out the data to be returnedweb server, And thenweb serverEncapsulatedhttp/httpsProtocol format, returned to the client/Browser

First, you need to know whether you use apache or nginx as the server. The real request is parsed by the server. After the server is configured, it is directly handed over to php for processing. If the server is useless, see @ mao's answer

$context = stream_context_create(array('ssl' =>array(        'local_cert' =>'./https.pem',    )));if(!$server = stream_socket_server("ssl://0.0.0.0:2016", $err_no, $err_msg, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context)){   exit($err_msg);}while(1){    $client = stream_socket_accept($server);    if ($client) {        stream_set_blocking($client, 0);        $in = '';        while($ret = fread($client, 8192)) $in .= $ret;        $response = "HTTP/1.0 200 OK\r\n\r\nHello";        fwrite($client, $response);        fclose($client);    }}

PHP can also write the Socket server. The above is an extremely simple HTTPS WebServer written in PHP. The local test passes and the browser accesses https: // 127.0.0.1: 2016 for testing.

Code in github https://github.com/walkor/webserver-example
There is also an HTTP WebServer, which is still a very simple Demo. The AB Pressure Test results are as follows, with a single core of 2.4 QPS.

Concurrency Level:      100Time taken for tests:   4.082 secondsComplete requests:      100000Failed requests:        0Write errors:           0Total transferred:      3100000 bytesHTML transferred:       1200000 bytesRequests per second:    24498.50 [#/sec] (mean)Time per request:       4.082 [ms] (mean)Time per request:       0.041 [ms] (mean, across all concurrent requests)Transfer rate:          741.65 [Kbytes/sec] received

For more powerful socket servers written in PHP, see here:
Https://github.com/walkor/workerman

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.