php async

· 2018-04-14 (토) 13:25:05 · 4339 · 3

[code]

// POST방식으로 fsockopen 통신 :: 리턴값은 없고 보내고 바로 커넥션을 끊는다
/*
    예제
        curl_async('http://example.com/test.php');
        curl_async('https://example.com/test.php');
        curl_async('/test.php');
*/
function curl_async($url) {
    $parts = parse_url($url);
    if(empty($parts['host'])) {
        $parts['scheme'] = '';
        $parts['host'] = reset(explode(':', $_SERVER['HTTP_HOST']));
        $parts['port'] = (count(explode(':', $_SERVER['HTTP_HOST'])) > 1?end(explode(':', $_SERVER['HTTP_HOST'])):80);
        if($parts['port'] != '80') $parts['scheme'] = 'https';
    }
    if(is_array($parts) && isset($parts['query'])) $post_string = $parts['query'];
    else $post_string = '';
    $fp = fsockopen(($parts['scheme'] == 'https'?'ssl://':null).$parts['host'], isset($parts['port'])?$parts['port']:80,  $errno, $errstr, 10);
    $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);
}

[/code]

리턴 없이 데이터를 수행 할때 유용합니다.

 

저같은 경우는 SMS인증 하기라든지 메일링 대량 발송등에 사용 하고 있습니다.

|

댓글 3개

값은 어떻게 전달하나요?
curl_async('https://example.com/test.php?aaa=1&bbb=2');
이렇게보내면 되나요?
2018-05-02 (수) 10:50:49
네!
주석을 참조하시면 됩니다!
네 감사합니다.. 잘 쓸게요~ ^^
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
기타 18-09-28 조회 8,915
jQuery 18-09-21 조회 6,442
기타 18-09-06 조회 3,319
PHP 18-08-29 조회 4,010
JavaScript 18-08-29 조회 6,901
MySQL 18-08-12 조회 3,722
MySQL 18-08-11 조회 3,399
PHP 18-07-31 조회 2,901
PHP 18-07-20 조회 3,298
기타 18-07-12 조회 3,687
PHP 18-07-12 조회 2,902
PHP 18-07-11 조회 4,257
PHP 18-07-06 조회 3,904
JavaScript 18-07-03 조회 3,901
JavaScript 18-06-26 조회 3,590
PHP 18-06-16 조회 6,094
PHP 18-06-05 조회 3,496
OS 18-05-02 조회 3,572
기타 18-05-01 조회 2,960
PHP 18-04-28 조회 3,308
웹서버 18-04-23 조회 2,940
PHP 18-04-14 조회 4,340
기타 18-03-27 조회 3,875
기타 18-03-23 조회 6,293
기타 18-03-16 조회 4,780
JavaScript 18-03-07 조회 5,154
PHP 18-03-02 조회 4,563
JavaScript 18-02-18 조회 4,986
PHP 18-01-30 조회 6,272
jQuery
[jQuery]
18-01-28 조회 3,189