Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp fixing php/api/curl code please
    primarykey
    data
    text
    <p>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.</p> <p>I would like to check the availability of the domain, multiple times (possibly on a loop?), <strong><em>without having to run restart cURL connection everytime (as it wastes time - 300ms to 1s per query)</em></strong>.</p> <p>I just don't know how I can connect to cURL once and run the loop (doing the check through the API). Help adjusting the code would be very much appreciated! Minimizing the time it takes to output "available/not available" and looping the checks is key.</p> <p>Thank you.</p> <p><strong>Current code</strong></p> <pre><code>&lt;?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)&lt;meta http-equiv="Expires"[^&gt;]*&gt;/i', '', $tmp); $tmp = explode('&lt;br&gt;', $tmp); echo $tmp[0]; echo "&lt;br&gt;"; echo $tmp[1]; echo "&lt;br&gt;"; return $tmp; } $returnUrl = "http://www.mysite.com.au/check.php"; $url = "https://www.apisite.com.au/availability/check.php?domain=testdomain&amp;suffixes=.com.au"; $output = GetCurlPage("$url"); ?&gt; </code></pre> <p><strong>@Marc B</strong></p> <pre><code> function getCurlPage($pageSpec) { if (is_null($ch)) { $ch = curl_init($pageSpec); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); } else { curl_setopt($ch, CURLOPT_URL, $pageSpec); } while ($i &lt; 5) { $tmp = curl_exec ($ch); //curl_close ($ch); $tmp = preg_replace('/(?s)&lt;meta http-equiv="Expires"[^&gt;]*&gt;/i', '', $tmp); $tmp = explode('&lt;br&gt;', $tmp); echo $tmp[0]; echo "&lt;br&gt;"; echo $tmp[1]; echo "&lt;br&gt;"; echo udate('H:i:s:u'); echo "&lt;br&gt;&lt;br&gt;"; $i++; } return $tmp; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload