0

I am wrting a script to check whether site down or not and using following php code to

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user ');

curl_setopt($ch, CURLOPT_NOBODY, true);
$return_val = curl_exec($ch);
$code =  curl_getinfo($ch, CURLINFO_HTTP_CODE );
var_dump($code);

It works fine for some sites but some sites like as mentioned in CURLOPT_URL options returns 400 code

http://www.djangobook.com/en/2.0/chapter10.html this url too doesn't work

I tried in my localhost as well as remote server but same thing happens

i also tried to add https://github.com/twilio/twilio-php/blob/master/Services/cacert.pem but still not working

What am i doing wrong ???

1
  • A 404 error is something actively sent by the requested server, not some transport problem or similar. Therefor, assumed that the urls you try are correct, it must be some active decision the server takes to answer with such error. It might for example be that this is an attempt to prevent page scrapers from reading content.
    – arkascha
    Apr 22, 2014 at 6:02

3 Answers 3

0

You ask for a HEAD on a specific URL. The server then says that the page/resource doesn't exist by sending you the 404 response back.

This is not a client problem really, the server says the page doesn't exist. If you get a different result without CURLOPT_NOBODY set (which is sometimes the case) then you can in fact blame the server for not being properly HTTP compliant but that won't make anyone happier.

(Other answers may involve details such as CURLOPT_SSL_VERIFYPEER and CURLOPT_RETURNTRANSFER but they are of course irrelevant here.)

0

Remove white space str_replace(" ", '%20', $url);

-2

You need to add this cURL param as you are calling a HTTPs URL.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

Also, you need to add this..

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

And comment of the curl_setopt($ch, CURLOPT_NOBODY, true); which is giving you the 404.

The working code..

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_NOBODY, true);
$return_val = curl_exec($ch);
$code =  curl_getinfo($ch, CURLINFO_HTTP_CODE );
var_dump($code);

OUTPUT :

int 200
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.