0

I have ann Array of urls

$arr = Array(
       'http://magento2.com/url-exist',
       'http://magento2.com/url-does-not-exist',
       'http://magento2.com/url-does-not-exist',
       'http://magento2.com/url-exist');

I've tried curl, get_headers they all failed

output is wrong:

<a href="http://magento2.com/url-exist" >Link-1</a>
<a href="http://magento2.com/url-does-not-exist" >Link-2</a>
<a href="http://magento2.com/url-does-not-exist" >Link-3</a>
<a href="http://magento2.com/url-exist" >Link-4</a>

It should return only url 1 and 4 200 status code e.g:

<a href="http://magento2.com/url-exist" >Link-1</a>
<a href="http://magento2.com/url-exist" >Link-4</a>

However it's returning all 200 but 2 and 3 should return 404

Anyone have any idea why ?

Thanks in advance!

4
  • When you go to http://magento2.com/url-does-not-exist you get 404 ?
    – Aamir
    Oct 29 '18 at 11:27
  • 1
    @prince Absolutely correct this url : magento2.com/url-does-not-exist returns 404 Oct 29 '18 at 11:28
  • So what is the issue if this url doesn't realy exist ?
    – Aamir
    Oct 29 '18 at 11:31
  • @PRINCE using I am looping the array to check status code using get_headers() (php.net/manual/en/function.get-headers.php) it shouldn't return all 200 if returns 404 then I don't include the link in the markup Oct 29 '18 at 11:35
0
  1. php bin/magento indexer:reindex, php bin/magento cache:clean

  2. <?php
    $arr = Array(
        "link 1" => 'http://magento2.com/url-exist',
        "link 2" => 'http://magento2.com/url-does-not-exist',
        "link 3" => 'http://magento2.com/url-does-not-exist',
        "link 4" => 'http://magento2.com/url-exist'
    );
    
    foreach($arr as $key=>$url)
        \Zend_Debug::dump($key.' = '.array_values(get_headers($url))[0]);
    ?>
    

    Result :

    string(24) "link 1 = HTTP/1.0 200 OK"
    
    string(31) "link 2 = HTTP/1.1 404 Not Found"
    
    string(31) "link 3 = HTTP/1.1 404 Not Found"
    
    string(24) "link 4 = HTTP/1.0 200 OK"
    
1
  • Thanks but that's exactly what I am doing. however in my local server works but In the remote server it doesn't so I've contact server support. thanks. Oct 29 '18 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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