LMSouq
php-dev Open

Getting HTTP code in PHP using curl

AA
Aaran McGuire
1 month ago
3 views
Problem Description
I'm using CURL to get the status of a site, if it's up/down or redirecting to another site. I want to get it as streamlined as possible, but it's not working well. <?php $ch = curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_TIMEOUT,10); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpcode; ?> I have this wrapped in a function. It works fine but performance is not the best because it downloads the whole page, thing in if I remove `$output = curl_exec($ch);` it returns `0` all the time. Does anyone know how to make the performance better?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base