0

I would write a WordPress plugin to parse all image source and check it's broken link or not. My idea is :

  1. Select all post&page's images by regex from MySQL
  2. Navigate the image url and get the response header (404 ,403 error etc)
  3. print a report

Since i don't need actual to download the binary file, so in performance ,compare in CURL , fopen , fsocketopen Which one is worst to use?

And one more question, which method can execute in multi-thread?

David
  • 208,112
  • 36
  • 198
  • 279
Cheung
  • 15,293
  • 19
  • 63
  • 93

1 Answers1

4

The cost of opening a connection to the remote server makes the performance of the library a fairly moot point. In other words it isn't worth worrying about the performance of the functions.

A better option would be to use wse whatever function allows you to make HEAD requests (Which only return the HTTP headers). While you can do it with fsockopen (I don't know about fopen), it is a lot of work when cURL has code already written to send the request and parse the response.

For an example of how to do a head request using cURL see this answer.

And one more question, which method can execute in multi-thread?

PHP doesn't have threads

Community
  • 1
  • 1
Yacoby
  • 54,544
  • 15
  • 116
  • 120
  • While it's true that php isn't threaded as such, please be sure to read up on the curl_multi* functions (http://www.php.net/manual/en/function.curl-multi-init.php), as it IS possible to pull multiple curl requests in parallel. For a more in-depth read on how one might go about this, may I highly recommend Stoyan Stefanov's write up: (http://www.phpied.com/simultaneuos-http-requests-in-php-with-curl/) – Bryan B. May 07 '12 at 14:19