Skip to content

Instantly share code, notes, and snippets.

@jdeathe
Last active February 8, 2019 19:45
Show Gist options
  • Select an option

  • Save jdeathe/c96f20e700634ac6c8fe51f9dcfb62a8 to your computer and use it in GitHub Desktop.

Select an option

Save jdeathe/c96f20e700634ac6c8fe51f9dcfb62a8 to your computer and use it in GitHub Desktop.

Revisions

  1. jdeathe revised this gist Feb 8, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions php-curl-status.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <?php

    $httpStatus = 500;
    $responseCode = 500;
    $responseCodeOk = 200;
    $responseCodeFail = 503;
    $url = 'https://www.deathe.org/';
    @@ -30,7 +30,7 @@
    $ch
    ) === 0
    ) {
    $httpStatus = curl_getinfo(
    $responseCode = curl_getinfo(
    $ch,
    CURLINFO_RESPONSE_CODE
    );
    @@ -50,7 +50,7 @@
    if (
    preg_match(
    '/^[23][0-9]{2}/',
    $httpStatus
    $responseCode
    ) !== 1
    ) {
    http_response_code(
  2. jdeathe revised this gist Feb 8, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion php-curl-status.php
    Original file line number Diff line number Diff line change
    @@ -63,4 +63,3 @@
    $responseCodeOk
    );
    print 'OK';
    exit;
  3. jdeathe revised this gist Feb 8, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions php-curl-status.php
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    <?php

    $url = 'https://www.deathe.org/';
    $httpStatus = 500;
    $responseCodeOk = 200;
    $responseCodeFail = 503;
    $url = 'https://www.deathe.org/';

    $ch = curl_init();

    @@ -24,13 +25,12 @@
    $ch
    );

    $http_status = 500;
    if (
    curl_errno(
    $ch
    ) === 0
    ) {
    $http_status = curl_getinfo(
    $httpStatus = curl_getinfo(
    $ch,
    CURLINFO_RESPONSE_CODE
    );
    @@ -50,7 +50,7 @@
    if (
    preg_match(
    '/^[23][0-9]{2}/',
    $http_status
    $httpStatus
    ) !== 1
    ) {
    http_response_code(
  4. jdeathe created this gist Feb 8, 2019.
    66 changes: 66 additions & 0 deletions php-curl-status.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    <?php

    $url = 'https://www.deathe.org/';
    $responseCodeOk = 200;
    $responseCodeFail = 503;

    $ch = curl_init();

    curl_setopt_array(
    $ch,
    array(
    CURLOPT_URL => $url,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_USERAGENT => 'Custom Status Check',
    CURLOPT_CONNECTTIMEOUT => 5,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_NOBODY => true,
    CURLOPT_HTTPGET => true,
    CURLOPT_RETURNTRANSFER => true
    )
    );

    curl_exec(
    $ch
    );

    $http_status = 500;
    if (
    curl_errno(
    $ch
    ) === 0
    ) {
    $http_status = curl_getinfo(
    $ch,
    CURLINFO_RESPONSE_CODE
    );
    }

    curl_close(
    $ch
    );

    header(
    'Cache-Control: no-cache'
    );
    header(
    'Content-Type: text/plain'
    );

    if (
    preg_match(
    '/^[23][0-9]{2}/',
    $http_status
    ) !== 1
    ) {
    http_response_code(
    $responseCodeFail
    );
    exit;
    }

    http_response_code(
    $responseCodeOk
    );
    print 'OK';
    exit;