S
S
stepbystep2020-09-14 21:56:55
Server equipment
stepbystep, 2020-09-14 21:56:55

Is it possible in php to handle 404 error in a loop?

Can you please tell me if the php loop will continue to iterate if one of the elements returns 404 ?

I implemented a small parser using simple_html_dom.php, I parse the page, look for the necessary data by class and save it. But some links "broken" returns 404 error and my cycle breaks, can I make it so that if 404 skips and goes to the next iteration?

foreach ($result_data as  $job) {

          $ref_code = $job->RefCode;

          if (!$ref_code ) {

            $image_url = 'https://mylink.com/' . $ref_code . '/';
            $html = file_get_html(rtrim($image_url));

            $headers = @get_headers($image_url); 

            if(strpos($string, "200")) { 

              $contact = $html->find( "." . 'contact-right', 0)->innertext;
              update_field( 'contact_details', $contact, $post_id );

              $img_src = $html->find( "." . 'contact-left' . ' > img', 0)->src;
              update_field( 'foto', $image_url . $img_src, $post_id );
            }


          }

        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2015-10-05
@xmoonlight

Just for a hobby: www.ulmart.ru/goods/932592

V
Vlad Zhivotnev, 2015-10-05
@inkvizitor68sl

In Microserver Gen8, you can put some kind of low-tdp Xeon (i7 of the same generation interferes with shit) and 32G RAM. Well, 4 hdd, yes.
And yet it is more designed for location in dusty rooms than rack servers (nets, grilles and all that).
Don't use hardware raids at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question