복붙노트

PHP에서 비동기 GET 요청을하는 방법은 무엇입니까?

PHP

PHP에서 비동기 GET 요청을하는 방법은 무엇입니까?

나는 다른 서버에있는 다른 스크립트에 간단한 GET 요청을하고 싶다. 어떻게해야합니까?

어떤 경우에는 출력이 필요없는 외부 스크립트를 요청하면됩니다.

make_request('http://www.externalsite.com/script1.php?variable=45'); //example usage

두 번째 경우에는 텍스트를 출력해야합니다.

$output = make_request('http://www.externalsite.com/script2.php?variable=45');
echo $output; //string output

솔직하게 말해서, 저는 이것이 CURL의 직업이 아니기 때문에 CURL을 어지럽히고 싶지는 않습니다. PECL 확장 기능이 없기 때문에 http_get을 사용하고 싶지도 않습니다.

fsockopen이 작동합니까? 그렇다면 파일의 내용을 읽지 않고 어떻게해야합니까? 다른 방법이 없습니까?

모두에게 감사합니다.

첫 번째 경우에는 스크립트가 아무 것도 반환 할 때까지 기다리지 않으려 고합니다. file_get_contents ()가 페이지가 완전히로드 될 때까지 기다릴 것이라고 알고 있습니까?

해결법

  1. ==============================

    1.file_get_contents가 원하는대로 할 것입니다.

    file_get_contents가 원하는대로 할 것입니다.

    $output = file_get_contents('http://www.example.com/');
    echo $output;
    

    편집 : GET 요청을 시작하고 즉시 반환하는 한 가지 방법.

    http://petewarden.typepad.com/searchbrowser/2008/06/how-to-post-an.html에서 인용

    function curl_post_async($url, $params)
    {
        foreach ($params as $key => &$val) {
          if (is_array($val)) $val = implode(',', $val);
            $post_params[] = $key.'='.urlencode($val);
        }
        $post_string = implode('&', $post_params);
    
        $parts=parse_url($url);
    
        $fp = fsockopen($parts['host'],
            isset($parts['port'])?$parts['port']:80,
            $errno, $errstr, 30);
    
        $out = "POST ".$parts['path']." HTTP/1.1\r\n";
        $out.= "Host: ".$parts['host']."\r\n";
        $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
        $out.= "Content-Length: ".strlen($post_string)."\r\n";
        $out.= "Connection: Close\r\n\r\n";
        if (isset($post_string)) $out.= $post_string;
    
        fwrite($fp, $out);
        fclose($fp);
    }
    

    이것은 소켓을 열고, get 요청을 실행하고, 즉시 소켓을 닫고 반환하는 것입니다.

  2. ==============================

    2.다음은 POST와 GET 요청 모두에 대한 Marquis의 대답을 만드는 방법입니다.

    다음은 POST와 GET 요청 모두에 대한 Marquis의 대답을 만드는 방법입니다.

      // $type must equal 'GET' or 'POST'
      function curl_request_async($url, $params, $type='POST')
      {
          foreach ($params as $key => &$val) {
            if (is_array($val)) $val = implode(',', $val);
            $post_params[] = $key.'='.urlencode($val);
          }
          $post_string = implode('&', $post_params);
    
          $parts=parse_url($url);
    
          $fp = fsockopen($parts['host'],
              isset($parts['port'])?$parts['port']:80,
              $errno, $errstr, 30);
    
          // Data goes in the path for a GET request
          if('GET' == $type) $parts['path'] .= '?'.$post_string;
    
          $out = "$type ".$parts['path']." HTTP/1.1\r\n";
          $out.= "Host: ".$parts['host']."\r\n";
          $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
          $out.= "Content-Length: ".strlen($post_string)."\r\n";
          $out.= "Connection: Close\r\n\r\n";
          // Data goes in the request body for a POST request
          if ('POST' == $type && isset($post_string)) $out.= $post_string;
    
          fwrite($fp, $out);
          fclose($fp);
      }
    
  3. ==============================

    3.업데이트에 관해서, 전체 페이지가로드 될 때까지 기다리지 않으려 고하는 것에 대해 - 나는 HTTP HEAD 요청이 당신이 찾고있는 것이라고 생각합니다.

    업데이트에 관해서, 전체 페이지가로드 될 때까지 기다리지 않으려 고하는 것에 대해 - 나는 HTTP HEAD 요청이 당신이 찾고있는 것이라고 생각합니다.

    get_headers가이 작업을 수행해야합니다. 헤더 만 요청하기 때문에 전체 페이지 콘텐츠가 전송되지 않습니다.

    "PHP / Curl : HEAD 요청은 일부 사이트에서 오랜 시간이 걸립니다"는 PHP / Curl을 사용하여 HEAD 요청을 수행하는 방법을 설명합니다

    요청을 트리거하고 스크립트를 전혀 보류하지 않으려면 몇 가지 방법으로 복잡성을 변경하십시오.

  4. ==============================

    4.너는하지 않는다. PHP는 URL을 호출 할 수있는 많은 방법을 제공하지만 요청 / 실행주기마다 비동기 / 스레드 처리를 수행하기위한 기본 지원을 제공하지 않습니다. URL (또는 SQL 문 또는 기타)에 대한 요청을 전송하는 모든 방법은 일종의 응답을 기다릴 것입니다. 이 일을 달성하기 위해 로컬 컴퓨터에서 실행되는 보조 시스템이 필요합니다 ( "php job queue"에 대한 google).

    너는하지 않는다. PHP는 URL을 호출 할 수있는 많은 방법을 제공하지만 요청 / 실행주기마다 비동기 / 스레드 처리를 수행하기위한 기본 지원을 제공하지 않습니다. URL (또는 SQL 문 또는 기타)에 대한 요청을 전송하는 모든 방법은 일종의 응답을 기다릴 것입니다. 이 일을 달성하기 위해 로컬 컴퓨터에서 실행되는 보조 시스템이 필요합니다 ( "php job queue"에 대한 google).

  5. ==============================

    5.나는 잘 테스트 된 PHP 라이브러리를 권할 것이다 : curl-easy

    나는 잘 테스트 된 PHP 라이브러리를 권할 것이다 : curl-easy

    <?php
    $request = new cURL\Request('http://www.externalsite.com/script2.php?variable=45');
    $request->getOptions()
        ->set(CURLOPT_TIMEOUT, 5)
        ->set(CURLOPT_RETURNTRANSFER, true);
    
    // add callback when the request will be completed
    $request->addListener('complete', function (cURL\Event $event) {
        $response = $event->response;
        $content = $response->getContent();
        echo $content;
    });
    
    while ($request->socketPerform()) {
        // do anything else when the request is processed
    }
    
  6. ==============================

    6.

    function make_request($url, $waitResult=true){
        $cmi = curl_multi_init();
    
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    
        curl_multi_add_handle($cmi, $curl);
    
        $running = null;
        do {
            curl_multi_exec($cmi, $running);
            sleep(.1);
            if(!$waitResult)
            break;
        } while ($running > 0);
        curl_multi_remove_handle($cmi, $curl);
        if($waitResult){
            $curlInfos = curl_getinfo($curl);
            if((int) $curlInfos['http_code'] == 200){
                curl_multi_close($cmi);
                return curl_multi_getcontent($curl);
            }
        }
        curl_multi_close($cmi);
    }
    
  7. ==============================

    7.재미있는 문제. 다른 서버에서 일부 프로세스 나 동작을 트리거하려고하지만 결과가 무엇이든 신경 쓰지 말고 스크립트를 계속 진행하기를 원합니다. cURL에 이런 일이 발생할 수있는 무언가가있을 수 있지만 cURL이 수행 할 수없는 경우 exec ()를 사용하여 호출을 수행하는 서버에서 다른 스크립트를 실행하는 것이 좋습니다. (일반적으로 사람들은 스크립트 호출의 결과를 원하므로 PHP가 프로세스를 트리거 할 수 있는지 확실하지 않습니다.) exec ()를 사용하면 wget 또는 file_get_conents ()로 요청하는 다른 PHP 스크립트를 실행할 수 있습니다. .

    재미있는 문제. 다른 서버에서 일부 프로세스 나 동작을 트리거하려고하지만 결과가 무엇이든 신경 쓰지 말고 스크립트를 계속 진행하기를 원합니다. cURL에 이런 일이 발생할 수있는 무언가가있을 수 있지만 cURL이 수행 할 수없는 경우 exec ()를 사용하여 호출을 수행하는 서버에서 다른 스크립트를 실행하는 것이 좋습니다. (일반적으로 사람들은 스크립트 호출의 결과를 원하므로 PHP가 프로세스를 트리거 할 수 있는지 확실하지 않습니다.) exec ()를 사용하면 wget 또는 file_get_conents ()로 요청하는 다른 PHP 스크립트를 실행할 수 있습니다. .

  8. ==============================

    8.권고 된 방법 대신 메시지 큐를 사용하는 것이 좋습니다. 요청을 보내는 것보다 조금 더 많은 작업이 필요하지만 더 나은 솔루션이라고 확신합니다.

    권고 된 방법 대신 메시지 큐를 사용하는 것이 좋습니다. 요청을 보내는 것보다 조금 더 많은 작업이 필요하지만 더 나은 솔루션이라고 확신합니다.

  9. ==============================

    9.내가 너에게 내 방식을 보여줄 게 ​​:)

    내가 너에게 내 방식을 보여줄 게 ​​:)

    서버에 nodejs가 설치되어 있어야합니다.

    (내 서버가 1000 초 요청을받는 데 2 ​​초 밖에 걸리지 않습니다.)

    우 rl. php :

    <?
    $urls = array_fill(0, 100, 'http://google.com/blank.html');
    
    function execinbackground($cmd) { 
        if (substr(php_uname(), 0, 7) == "Windows"){ 
            pclose(popen("start /B ". $cmd, "r"));  
        } 
        else { 
            exec($cmd . " > /dev/null &");   
        } 
    } 
    fwite(fopen("urls.txt","w"),implode("\n",$urls);
    execinbackground("nodejs urlscript.js urls.txt");
    // { do your work while get requests being executed.. }
    ?>
    

    urlscript.js>

    var https = require('https');
    var url = require('url');
    var http = require('http');
    var fs = require('fs');
    var dosya = process.argv[2];
    var logdosya = 'log.txt';
    var count=0;
    http.globalAgent.maxSockets = 300;
    https.globalAgent.maxSockets = 300;
    
    setTimeout(timeout,100000); // maximum execution time (in ms)
    
    function trim(string) {
        return string.replace(/^\s*|\s*$/g, '')
    }
    
    fs.readFile(process.argv[2], 'utf8', function (err, data) {
        if (err) {
            throw err;
        }
        parcala(data);
    });
    
    function parcala(data) {
        var data = data.split("\n");
        count=''+data.length+'-'+data[1];
        data.forEach(function (d) {
            req(trim(d));
        });
        /*
        fs.unlink(dosya, function d() {
            console.log('<%s> file deleted', dosya);
        });
        */
    }
    
    
    function req(link) {
        var linkinfo = url.parse(link);
        if (linkinfo.protocol == 'https:') {
            var options = {
            host: linkinfo.host,
            port: 443,
            path: linkinfo.path,
            method: 'GET'
        };
    https.get(options, function(res) {res.on('data', function(d) {});}).on('error', function(e) {console.error(e);});
        } else {
        var options = {
            host: linkinfo.host,
            port: 80,
            path: linkinfo.path,
            method: 'GET'
        };        
    http.get(options, function(res) {res.on('data', function(d) {});}).on('error', function(e) {console.error(e);});
        }
    }
    
    
    process.on('exit', onExit);
    
    function onExit() {
        log();
    }
    
    function timeout()
    {
    console.log("i am too far gone");process.exit();
    }
    
    function log() 
    {
        var fd = fs.openSync(logdosya, 'a+');
        fs.writeSync(fd, dosya + '-'+count+'\n');
        fs.closeSync(fd);
    }
    
  10. ==============================

    10.Linux 환경을 사용하고 있다면 PHP의 exec 명령을 사용하여 Linux 컬을 호출 할 수 있습니다. 다음은 비동기 HTTP 게시물을 작성하는 샘플 코드입니다.

    Linux 환경을 사용하고 있다면 PHP의 exec 명령을 사용하여 Linux 컬을 호출 할 수 있습니다. 다음은 비동기 HTTP 게시물을 작성하는 샘플 코드입니다.

    function _async_http_post($url, $json_string) {
      $run = "curl -X POST -H 'Content-Type: application/json'";
      $run.= " -d '" .$json_string. "' " . "'" . $url . "'";
      $run.= " > /dev/null 2>&1 &";
      exec($run, $output, $exit);
      return $exit == 0;
    }
    

    이 코드는 추가 PHP 라이브러리가 필요하지 않으며 10 밀리 초 이내에 http 게시를 완료 할 수 있습니다.

  11. ==============================

    11.나에게 비동기 GET 요청에 대한 질문은 내가 수백 건의 요청을 할 필요가 있고 모든 요청에 ​​대한 결과 데이터를 얻고 처리해야 할 때 상황을 만났기 때문에 나타난다. 그리고 모든 요청은 상당한 밀리 초의 실행 시간을 필요로한다. 간단한 file_get_contents로 실행되는 총.

    나에게 비동기 GET 요청에 대한 질문은 내가 수백 건의 요청을 할 필요가 있고 모든 요청에 ​​대한 결과 데이터를 얻고 처리해야 할 때 상황을 만났기 때문에 나타난다. 그리고 모든 요청은 상당한 밀리 초의 실행 시간을 필요로한다. 간단한 file_get_contents로 실행되는 총.

    이 경우 함수 http://php.net/manual/en/function.curl-multi-init.php에서 php.net의 w_haigh에 대한 매우 유용한 설명이었습니다.

    그래서, 여기에 많은 요청을 동시에 내 업그레이드하고 정리 한 버전이 있습니다. 제 경우에는 "비동기"와 같습니다. 누군가에게 도움이 될지도!

    // Build the multi-curl handle, adding both $ch
    $mh = curl_multi_init();
    
    // Build the individual requests, but do not execute them
    $chs = [];
    $chs['ID0001'] = curl_init('http://webservice.example.com/?method=say&word=Hello');
    $chs['ID0002'] = curl_init('http://webservice.example.com/?method=say&word=World');
    // $chs[] = ...
    foreach ($chs as $ch) {
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,  // Return requested content as string
            CURLOPT_HEADER => false,         // Don't save returned headers to result
            CURLOPT_CONNECTTIMEOUT => 10,    // Max seconds wait for connect
            CURLOPT_TIMEOUT => 20,           // Max seconds on all of request
            CURLOPT_USERAGENT => 'Robot YetAnotherRobo 1.0',
        ]);
    
        // Well, with a little more of code you can use POST queries too
        // Also, useful options above can be  CURLOPT_SSL_VERIFYHOST => 0  
        // and  CURLOPT_SSL_VERIFYPEER => false ...
    
        // Add every $ch to the multi-curl handle
        curl_multi_add_handle($mh, $ch);
    }
    
    // Execute all of queries simultaneously, and continue when ALL OF THEM are complete
    $running = null;
    do {
        curl_multi_exec($mh, $running);
    } while ($running);
    
    // Close the handles
    foreach ($chs as $ch) {
        curl_multi_remove_handle($mh, $ch);
    }
    curl_multi_close($mh);
    
    // All of our requests are done, we can now access the results
    // With a help of ids we can understand what response was given
    // on every concrete our request
    $responses = [];
    foreach ($chs as $id => $ch) {
        $responses[$id] = curl_multi_getcontent($ch);
        curl_close($ch);
    }
    unset($chs); // Finita, no more need any curls :-)
    
    print_r($responses); // output results
    

    POST 또는 다른 유형의 HTTP (S) 요청 또는 그 조합을 처리하기 위해 이것을 다시 작성하는 것은 쉽습니다. 쿠키 지원, 리디렉션, http-auth 등

  12. ==============================

    12.시험:

    시험:

    //Your Code here
    $pid = pcntl_fork();
    if ($pid == -1) {
         die('could not fork');
    }
    else if ($pid)
    {
    echo("Bye")  
    }
    else
    {
         //Do Post Processing
    }
    

    이것은 아파치 모듈로 작동하지 않을 것이다. CGI를 사용해야한다.

  13. ==============================

    13.비동기 처리 (요청 받기)를 수행하는 흥미로운 링크를 발견했습니다.

    비동기 처리 (요청 받기)를 수행하는 흥미로운 링크를 발견했습니다.

    탈출

    또한 Beanstalkd와 같은 메시지 대기열을 사용하여 비동기 처리를 수행 할 수 있습니다.

  14. ==============================

    14.다음은 간단한 GET 요청을 수행 할 때 허용되는 답변의 변형입니다.

    다음은 간단한 GET 요청을 수행 할 때 허용되는 답변의 변형입니다.

    서버가 URL을 다시 작성하는 경우 한 가지주의해야 할 것은 작동하지 않습니다. 더 많은 기능을 갖춘 http 클라이언트를 사용해야합니다.

      /**
       * Performs an async get request (doesn't wait for response)
       * Note: One limitation of this approach is it will not work if server does any URL rewriting
       */
      function async_get($url)
      {
          $parts=parse_url($url);
    
          $fp = fsockopen($parts['host'],
              isset($parts['port'])?$parts['port']:80,
              $errno, $errstr, 30);
    
          $out = "GET ".$parts['path']." HTTP/1.1\r\n";
          $out.= "Host: ".$parts['host']."\r\n";
          $out.= "Connection: Close\r\n\r\n";
          fwrite($fp, $out);
          fclose($fp);
      }
    
  15. ==============================

    15.Guzzle은 HTTP 요청을 쉽게 보낼 수있는 PHP HTTP 클라이언트입니다. Curl을 사용하거나 사용하지 않고 작업 할 수 있습니다. 그것은 동기 및 비동기 요청을 보낼 수 있습니다.

    Guzzle은 HTTP 요청을 쉽게 보낼 수있는 PHP HTTP 클라이언트입니다. Curl을 사용하거나 사용하지 않고 작업 할 수 있습니다. 그것은 동기 및 비동기 요청을 보낼 수 있습니다.

    $client = new GuzzleHttp\Client();
    $promise = $client->requestAsync('GET', 'http://httpbin.org/get');
    $promise->then(
        function (ResponseInterface $res) {
            echo $res->getStatusCode() . "\n";
        },
        function (RequestException $e) {
            echo $e->getMessage() . "\n";
            echo $e->getRequest()->getMethod();
        }
    );
    
  16. ==============================

    16.이 스레드를 기반으로 내 codeigniter 프로젝트에 이것을 만들었습니다. 그것은 잘 작동합니다. 백그라운드에서 모든 기능을 처리 할 수 ​​있습니다.

    이 스레드를 기반으로 내 codeigniter 프로젝트에 이것을 만들었습니다. 그것은 잘 작동합니다. 백그라운드에서 모든 기능을 처리 할 수 ​​있습니다.

    비동기 호출을 허용하는 컨트롤러입니다.

    class Daemon extends CI_Controller
    {
        // Remember to disable CI's csrf-checks for this controller
    
        function index( )
        {
            ignore_user_abort( 1 );
            try
            {
                if ( strcmp( $_SERVER['REMOTE_ADDR'], $_SERVER['SERVER_ADDR'] ) != 0 && !in_array( $_SERVER['REMOTE_ADDR'], $this->config->item( 'proxy_ips' ) ) )
                {
                    log_message( "error", "Daemon called from untrusted IP-address: " . $_SERVER['REMOTE_ADDR'] );
                    show_404( '/daemon' );
                    return;
                }
    
                $this->load->library( 'encrypt' );
                $params = unserialize( urldecode( $this->encrypt->decode( $_POST['data'] ) ) );
                unset( $_POST );
                $model = array_shift( $params );
                $method = array_shift( $params );
                $this->load->model( $model );
                if ( call_user_func_array( array( $this->$model, $method ), $params ) === FALSE )
                {
                    log_message( "error", "Daemon could not call: " . $model . "::" . $method . "()" );
                }
            }
            catch(Exception $e)
            {
                log_message( "error", "Daemon has error: " . $e->getMessage( ) . $e->getFile( ) . $e->getLine( ) );
            }
        }
    }
    

    그리고 비동기 호출을하는 라이브러리

    class Daemon
    {
        public function execute_background( /* model, method, params */ )
        {
            $ci = &get_instance( );
            // The callback URL (its ourselves)
            $parts = parse_url( $ci->config->item( 'base_url' ) . "/daemon" );
            if ( strcmp( $parts['scheme'], 'https' ) == 0 )
            {
                $port = 443;
                $host = "ssl://" . $parts['host'];
            }
            else 
            {
                $port = 80;
                $host = $parts['host'];
            }
            if ( ( $fp = fsockopen( $host, isset( $parts['port'] ) ? $parts['port'] : $port, $errno, $errstr, 30 ) ) === FALSE )
            {
                throw new Exception( "Internal server error: background process could not be started" );
            }
            $ci->load->library( 'encrypt' );
            $post_string = "data=" . urlencode( $ci->encrypt->encode( serialize( func_get_args( ) ) ) );
            $out = "POST " . $parts['path'] . " HTTP/1.1\r\n";
            $out .= "Host: " . $host . "\r\n";
            $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $out .= "Content-Length: " . strlen( $post_string ) . "\r\n";
            $out .= "Connection: Close\r\n\r\n";
            $out .= $post_string;
            fwrite( $fp, $out );
            fclose( $fp );
        }
    }
    

    이 메소드는 'background'에서 model :: method ()를 처리하기 위해 호출 할 수 있습니다. 변수 인수를 사용합니다.

    $this->load->library('daemon');
    $this->daemon->execute_background( 'model', 'method', $arg1, $arg2, ... );
    
  17. ==============================

    17.제안 : 안쪽에 9 개의 프레임이 들어있는 FRAMESET HTML 페이지를 포맷하십시오. 각 프레임은 myapp.php 페이지의 다른 "인스턴스"를 가져옵니다. 웹 서버에서 9 개의 다른 스레드가 병렬로 실행됩니다.

    제안 : 안쪽에 9 개의 프레임이 들어있는 FRAMESET HTML 페이지를 포맷하십시오. 각 프레임은 myapp.php 페이지의 다른 "인스턴스"를 가져옵니다. 웹 서버에서 9 개의 다른 스레드가 병렬로 실행됩니다.

  18. ==============================

    18.위에 게시 된 스크립트에 대한 몇 가지 수정. 다음은 나를 위해 일하고있다.

    위에 게시 된 스크립트에 대한 몇 가지 수정. 다음은 나를 위해 일하고있다.

    function curl_request_async($url, $params, $type='GET')
        {
            $post_params = array();
            foreach ($params as $key => &$val) {
                if (is_array($val)) $val = implode(',', $val);
                $post_params[] = $key.'='.urlencode($val);
            }
            $post_string = implode('&', $post_params);
    
            $parts=parse_url($url);
            echo print_r($parts, TRUE);
            $fp = fsockopen($parts['host'],
                (isset($parts['scheme']) && $parts['scheme'] == 'https')? 443 : 80,
                $errno, $errstr, 30);
    
            $out = "$type ".$parts['path'] . (isset($parts['query']) ? '?'.$parts['query'] : '') ." HTTP/1.1\r\n";
            $out.= "Host: ".$parts['host']."\r\n";
            $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
            $out.= "Content-Length: ".strlen($post_string)."\r\n";
            $out.= "Connection: Close\r\n\r\n";
            // Data goes in the request body for a POST request
            if ('POST' == $type && isset($post_string)) $out.= $post_string;
            fwrite($fp, $out);
            fclose($fp);
        }
    
  19. ==============================

    19.PHP5.5 +의 경우 mpyw / co가 궁극적 인 솔루션입니다. JavaScript에서 tj / co 인 것처럼 작동합니다.

    PHP5.5 +의 경우 mpyw / co가 궁극적 인 솔루션입니다. JavaScript에서 tj / co 인 것처럼 작동합니다.

    지정된 여러 GitHub 사용자의 아바타를 다운로드한다고 가정합니다. 각 사용자에 대해 다음 단계가 필요합니다.

    --- : 내 대답을 기다리고 있습니다. ... : 병렬 흐름으로 다른 응답 대기

    많은 유명한 curl_multi 기반 스크립트는 이미 다음과 같은 흐름을 제공합니다.

            /-----------GET HTML\  /--GET IMAGE.........\
           /                     \/                      \ 
    [Start] GET HTML..............----------------GET IMAGE [Finish]
           \                     /\                      /
            \-----GET HTML....../  \-----GET IMAGE....../
    

    그러나 이것은 충분히 효율적이지 않습니다. 쓸모없는 대기 시간을 줄이기를 원하십니까?

            /-----------GET HTML--GET IMAGE\
           /                                \            
    [Start] GET HTML----------------GET IMAGE [Finish]
           \                                /
            \-----GET HTML-----GET IMAGE.../
    

    예, mpyw / co에서 매우 쉽습니다. 자세한 내용은 저장소 페이지를 참조하십시오.

  20. ==============================

    20.어떤 페이지의 특정 URL에 POST 할 때 내 자신의 PHP 함수는 다음과 같습니다 ....

    어떤 페이지의 특정 URL에 POST 할 때 내 자신의 PHP 함수는 다음과 같습니다 ....

    샘플 : * 내 기능의 사용법 ...

    <?php
        parse_str("email=myemail@ehehehahaha.com&subject=this is just a test");
        $_POST['email']=$email;
        $_POST['subject']=$subject;
        echo HTTP_Post("http://example.com/mail.php",$_POST);***
    
        exit;
    ?>
    <?php
        /*********HTTP POST using FSOCKOPEN **************/
        // by ArbZ
    
        function HTTP_Post($URL,$data, $referrer="") {
    
        // parsing the given URL
        $URL_Info=parse_url($URL);
    
        // Building referrer
        if($referrer=="") // if not given use this script as referrer
          $referrer=$_SERVER["SCRIPT_URI"];
    
        // making string from $data
        foreach($data as $key=>$value)
          $values[]="$key=".urlencode($value);
        $data_string=implode("&",$values);
    
        // Find out which port is needed - if not given use standard (=80)
        if(!isset($URL_Info["port"]))
          $URL_Info["port"]=80;
    
        // building POST-request: HTTP_HEADERs
        $request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
        $request.="Host: ".$URL_Info["host"]."\n";
        $request.="Referer: $referer\n";
        $request.="Content-type: application/x-www-form-urlencoded\n";
        $request.="Content-length: ".strlen($data_string)."\n";
        $request.="Connection: close\n";
        $request.="\n";
        $request.=$data_string."\n";
    
        $fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
        fputs($fp, $request);
        while(!feof($fp)) {
            $result .= fgets($fp, 128);
        }
        fclose($fp); //$eco = nl2br();
    
        function getTextBetweenTags($string, $tagname) {
            $pattern = "/<$tagname ?.*>(.*)<\/$tagname>/";
            preg_match($pattern, $string, $matches);
            return $matches[1]; }
        //STORE THE FETCHED CONTENTS to a VARIABLE, because its way better and fast...
        $str = $result;
        $txt = getTextBetweenTags($str, "span"); $eco = $txt;  $result = explode("&",$result);
        return $result[1];
    <span style=background-color:LightYellow;color:blue>".trim($_GET['em'])."</span>
    </pre> "; 
    }
    </pre>
    
  21. ==============================

    21.이 코드를 사용해보십시오 ....

    이 코드를 사용해보십시오 ....

    $chu = curl_init();
    
    curl_setopt($chu, CURLOPT_URL, 'http://www.myapp.com/test.php?someprm=xyz');
    
    curl_setopt($chu, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($chu, CURLOPT_TIMEOUT, 1);
    
    curl_exec($chu);
    curl_close($chu);
    

    CURL PHP 확장 기능을 사용하는 것을 잊지 마십시오.

  22. ==============================

    22.이것은 나를 위해 잘 작동합니다, 슬프게도 당신의 요청에서 응답을 검색 할 수 없습니다 :

    이것은 나를 위해 잘 작동합니다, 슬프게도 당신의 요청에서 응답을 검색 할 수 없습니다 :

    <?php
    header("http://mahwebsite.net/myapp.php?var=dsafs");
    ?>
    

    그것은 아주 빨리, 원시 TCP 소켓에 대한 필요가 작동합니다 :)

  23. from https://stackoverflow.com/questions/962915/how-do-i-make-an-asynchronous-get-request-in-php by cc-by-sa and MIT license