0

What I have in place, is a domain availability check, which connects up to an API and outputs "Available: and Unavailable:" from $tmp. Ths below code will only check the availability ONCE.

I would like to check the availability of the domain, multiple times (possibly on a loop?), without having to run restart cURL connection everytime (as it wastes time).

I just don't know how I can connect to cURL once and run the loop (doing the check through the API).

Current code

<?php

    function GetCurlPage ($pageSpec)
    {
      $ch = curl_init($pageSpec);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      $tmp = curl_exec ($ch);
      curl_close ($ch);
      $tmp = preg_replace('/(?s)<meta http-equiv="Expires"[^>]*>/i', '', $tmp);
      $tmp = explode('<br>', $tmp);
      echo $tmp[0];
      echo "<br>";
      echo $tmp[1];
      echo "<br>";
      return $tmp;
    }

$returnUrl = "http://www.mysite.com.au/check.php";
$url = "https://www.apisite.com.au/availability/check.php?domain=testdomain&suffixes=.com.au";
$output = GetCurlPage("$url");

?>
hakre
  • 193,403
  • 52
  • 435
  • 836
iCeR
  • 77
  • 1
  • 7
  • Really not sure if I get your problem correctly. But there is no " *connecting once **to** cURL* ". Curl is an API for making requests (HTTP being a side job). It retrieves one page per request. There is no persistent connection or constant data flow (unless WebSocket supported) to be reused for *multiple* requests. – mario Dec 19 '10 at 07:28
  • Ok so the problem is this; I need the above script to check the availability of the domain specificed in $url ($domain+$suffixes), multiple times, ie: in a loop. I can run the bottom of the script (outside of the cURL function) in a loop, but if I do that, curl is initialized and executed all over again. This wastes 300ms to 1s between availability checks. What can I do to reduce the time in execution of a loop and where can the loop be placed? Hope this helps, sorry. Thanks! – iCeR Dec 19 '10 at 13:01

1 Answers1

0

link textI think you're after the callback options documented. For example --> CURLOPT_SEEKFUNCTION

willemIP
  • 21
  • 2