How PHP handles HTTPS requests

Source: Internet
Author: User
How can I use PHP to handle HTTPS requests?
What I want to ask is not to use curl to send a request, or to ask the principle of HTTPS, I just want to know what the PHP needs to do after sending the HTTPS request, or write what code to handle the request, can you have sample code?
Online search, not curl send HTTPS request example, is the example of https principle, but the principle I understand but do not know the beginning ...
Thank you

Reply content:

How can I use PHP to handle HTTPS requests?
What I want to ask is not to use curl to send a request, or to ask the principle of HTTPS, I just want to know what the PHP needs to do after sending the HTTPS request, or write what code to handle the request, can you have sample code?
Online search, not curl send HTTPS request example, is the example of https principle, but the principle I understand but do not know the beginning ...
Thank you

phphttpsIt's not about half a dime, because PHP is a language/script interpreter, not a server

A request arrives at the server, whether or not, http https through, for example, a web server apache nginx web server http/https Protocol-based data interaction between the processing and the client

Depending on the rules (such as the extension) to determine whether calls are required php to process the request, there are many ways to invoke it, such as the way, the way 模块 CGI , and the CGI-based fastcgi/fpm approach, depending on web server the configuration

After the call is finished, the php data to be returned is spit out and web server then web server packaged into http/https protocol format, returned to the client/browser

First you need to know whether you are using Apache or Nginx server, the real request is the server to parse. After the server is configured, it will be processed directly to PHP. If you don't use a server, see the answer to @mao's shoes.

$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, which is written in PHP with a very simple https webserver, local test pass, browser access to the HTTPS://127.0.0.1:2016 test

Put the code in GitHub https://github.com/walkor/webserver-example
There's an HTTP protocol in the webserver, which is still extremely humble. Demo,ab the results are as follows, single core 2.4W 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

PHP write more powerful socket server 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.