2

What could be causes of the page not loading? I'm currently sending a request to my bot which sends me a response back but somehow, if the bot is online and working, the page doesn't load. Is there a way to get the error? I have a cPanel and display_errors is 1. Any other ideas?

This is one of my requests:

function getData($Id) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"http://IPAdress:8000/Data/".$Id);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    $server_output = curl_exec($ch);
    curl_close ($ch);

   return $server_output;
}

1 Answer 1

2

curl_errno() and curl_error() usually suffice,

$server_output = curl_exec($ch);
$errstr=null;
if(curl_errno($ch)){
    $errstr = curl_errno($ch).": ".curl_error($ch);
}
curl_close ($ch);
if(isset($errstr)){
    echo $errstr;
}

sometimes you can get even more information by adding CURLOPT_VERBOSE

$stderrh=tmpfile();
curl_setopt_array($ch,array(CURLOPT_VERBOSE=>1,CURLOPT_STDERR=>$stderrh));
$server_output = curl_exec($ch);
/* https://bugs.php.net/bug.php?id=76268 */
rewind($stderrh); 
$stderr=stream_get_contents($stderrh);
fclose($stderrh);
$errstr=null;
if(curl_errno($ch)){
    $errstr = curl_errno($ch).": ".curl_error($ch)." verbose: ".$stderr;
}
curl_close ($ch);
if(isset($errstr)){
    echo $errstr;
}

but that's usually kindof overkill

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for your reply. This seems to print the error! But the whole website isn't loading when the bot is online - even pages I don't use cURL aren't loading. Any ideas on the cause of this?
@Neeko do you have access to the php errorlog? anyway could lots of things, could be something as stupid as hitting a die();, could also be that it's crashing inside a ob_start(); , but usually it's because display_errors is 0/off, does phpinfo() actually confirm that display_errors is 1? (regardless of what your cpanel setting is)
Hey, display errors is on (checked with phpinfo) - no error_log is being generated. I don't use any ob_start() or something similiar to that. Website works flawless if bot is offline and stops working if it's online, pages are perma-loading and not a single error (besides that I can't even reach the page to see if there's an error).
@Neeko ohh perma-loading? then it's probably a CURLOPT_TIMEOUT / CURLOPT_CONNECTTIMEOUT issue, try curl_setopt_array($ch,array(CURLOPT_CONNECTTIMEOUT=>3,CURLOPT_TIMEOUT=>5)); and see if that makes a difference.
Thanks for your suggestion - sadly that didn't work either. If I try to go from the hopepage to a page that sends requests it's perma-loading and during that time I'm always on the homepage.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.