To find an available socket instance

Source: Internet
Author: User
Socket instance

Get remote file with file_get_contents, return error, connect not on.
Someone online says you can use a socket. Did not use, ah, searched a bit is you turn me I turn you, for the first contact of the people can not be a strong operation AH.
My current requirement is to write the thief program and copy the content from someone else's website.

The articles that introduce sockets refer to "server-side programs" and "Client programs."
I have a place that I don't understand:
Where is the service-side program placed? is the Web site accessed on the server? That should not matter to me (do not write), I just need to write the client program?

Examples please hard code to www.baidu.com as an example thanks!!


Reply to discussion (solution)

The socket is not where it is divided, but it listens on one side as the server side, requesting the connection to the client side.

If you just want to grab something, the socket is too difficult for you, no need, with curl, search this version, related posts are more

File_get_contents, what's wrong?

File_get_contents, what's wrong?

The connection attempt failed because the connecting party did not reply correctly after a period of time or the connected host did not respond

The other side made a limit, try to use curl to try.

The socket is not where it is divided, but it listens on one side as the server side, requesting the connection to the client side.

If you just want to grab something, the socket is too difficult for you, no need, with curl, search this version, related posts are more
If you can use it, you don't need a socket.



Create a new Curl resource
$ch = Curl_init ();

Set the URL and the appropriate options
curl_setopt ($ch, Curlopt_url, "http://bbs.csdn.net/topics/380240079");
curl_setopt ($ch, Curlopt_header, 0);

Crawl the URL and pass it to the browser
Var_dump (Curl_exec ($ch));

Turn off the Curl resource and release the system resources
Curl_close ($ch);


returns False if n links are changed. Send a friend to try and he says he's over there return true

No, you can't do that, can you?

No, you can't do that, can you?

Here's the code I tried:

Create a new Curl resource
$ch = Curl_init ();

Set the URL and the appropriate options
curl_setopt ($ch, Curlopt_url, "http://bbs.csdn.net/topics/380240079");
curl_setopt ($ch, Curlopt_header, 0);

Crawl the URL and pass it to the browser
Var_dump (Curl_exec ($ch));

Turn off the Curl resource and release the system resources
Curl_close ($ch);

No way.

Brother, give me a try?

Crawl Web pages with curl.

You can come out with your code.

You can come out with your code.

It was possible to go home yesterday. It's weird.

Find one and try it:

function Read_file ($url) {  $r = @file_get_contents ($url);  if (! $r) {    $ch = Curl_init ();       curl_setopt ($ch, Curlopt_url, $url);            Set the URL address of the Access       //curl_setopt ($ch, curlopt_header,1);            Whether to display head information       curl_setopt ($ch, Curlopt_timeout, 5);           Set timeout       curl_setopt ($ch, curlopt_useragent, _useragent_);   User Access Agent User-agent       curl_setopt ($ch, curlopt_referer,_referer_);        Set Referer       curl_setopt ($ch, curlopt_followlocation,1);      Trace 301       curl_setopt ($ch, Curlopt_returntransfer, 1);        Returns the result       $r = curl_exec ($ch);    Curl_close ($ch);  }  return $r;   }

No, it means that your curl extension is not turned on, but even if file_get_contents can't access the URL, curl is mostly black-and-open.

No, it means that your curl extension is not turned on, but even if file_get_contents can't access the URL, curl is mostly black-and-open.
The extension opens

I tried in the company, no matter with file_get_contents, curl can not. Go home and try. I wonder if it has anything to do with the Internet?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.