Curl socket fsockopen
How do I understand socket fsockopen curl? What are their relationships and differences? What are the other parameters? Do you have any good information?
Reply to discussion (solution)
Socket is a connection method, for example, used to connect interfaces.
For example:
$ Fp = @ fsockopen ('address', 'port'); $ command = "" // write the data you want to send here, can be spliced. If (! Fwrite ($ fp, $ command) {exit ('error') ;}$ response = ''; // result set while (! Feof ($ fp) {$ str = fgets ($ fp, 1024); // read each row of data $ response. = $ str; // read each row to the result set} echo $ response; // output the result
Curl can be transmitted through a url. it is usually used to simulate an action, such as simulated logon.
Can it be detailed?
You can understand socket as a communication.
Fsockopen ('connection address', 'Port number ', 'error codeny', 'error information', 'timeout'); the parameter is the connection address.
The connection between socket and curl is irrelevant.
Curl's understanding, such:
Generally, when we request an interface, the data of the other party may have been encrypted.
Therefore, we have to use curl for encrypted transmission during the request, because normally we cannot know the encrypted data content.
Socket is a tool library for TCP/IP communication protocol. it is used to simplify the writing of TCP/IP communication programs.
Fsockopen is simple socket packaging
Curl is another tool library for TCP/IP communication protocol
Why?
$ Out = "GET $ path HTTP/1.1 \ r \ n ";
$ Out. = "Accept: */* \ r \ n ";
$ Out. = "Referer:". $ siteurl. "\ r \ n ";
$ Out. = "Accept-Language: zh-cn \ r \ n ";
$ Out. = "User-Agent: $ _ SERVER [HTTP_USER_AGENT] \ r \ n ";
$ Out. = "Host: $ host \ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
$ Out. = "Cookie: $ cookie \ r \ n"; for example
Socket can interact with servers (games, email, desktop software), transfer data, and so on!
Socket is an abstract socket and does not belong to PHP or other languages.
Fsocket is PHP's socket encapsulation, and C contains similar encapsulation.
Curl seems to be an exclusive PHP class library dedicated to simplifying socket operations. many host vendors block fsocket, but it also supports curl and Baidu BAE.
------------------------------------------------------ AutoCSDN signature file ------------------------------------------------------
Code Farm ?? A farm where coders sow codes and graze ideas!
$ Out = "GET $ path HTTP/1.1 \ r \ n ";
$ Out. = "Accept: */* \ r \ n ";
$ Out. = "Referer:". $ siteurl. "\ r \ n ";
$ Out. = "Accept-Language: zh-cn \ r \ n ";
$ Out. = "User-Agent: $ _ SERVER [HTTP_USER_AGENT] \ r \ n ";
$ Out. = "Host: $ host \ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
$ Out. = "Cookie: $ cookie \ r \ n"; for example
These request headers are not specified. The key is your needs.
$ Out = "GET $ path HTTP/1.1 \ r \ n ";
$ Out. = "Accept: */* \ r \ n ";
$ Out. = "Referer:". $ siteurl. "\ r \ n ";
$ Out. = "Accept-Language: zh-cn \ r \ n ";
$ Out. = "User-Agent: $ _ SERVER [HTTP_USER_AGENT] \ r \ n ";
$ Out. = "Host: $ host \ r \ n ";
$ Out. = "Connection: Close \ r \ n ";
$ Out. = "Cookie: $ cookie \ r \ n"; for example
These request headers are not specified. The key is your needs. What is the reason for this demand?
Protocol
Since it is communication, there must be an agreement. The value is the protocol.
Otherwise, you cannot speak English when I speak Russian.
Socket cement, sand, underlying things
Fsockopen cement premade, which can be used to build a house
Curl: the gray room can be renovated by yourself.
Cement and sand can not only build houses, but also build roads, bridges, and large sculptures. The socket is also used for not only webpage transmission, but also for transmitting other things. it can be used as chat tools, downloaders, ftp ...... Almost everything that can be transmitted over the network can be written using it. of course, there is a lot of knowledge to be mastered, for example, building a wall requires you to know how to keep the wall straight, hard to fall, antifreezing, and heat insulation.
You don't need to worry about whether the premade parts are straight, how the structure is, and how they are insulated. these creators can help you think about it. what you want is to build the shape you want. Fsockopen is, you can ignore the use of creat, connect, send, recv and other functions in the socket, and open it directly.
The rough room is simpler, and you can live with decoration. The simplest way is to brush the wall. but if you want to be more comfortable, you can use more and better decoration materials. but what's the disadvantage ?? This is a house. you cannot transform it into a river crossing or a transportation purpose.
The same is true for curl. all kinds of connections are done for you, and the underlying fault tolerance processing is done. you can pass the parameter to get the desired result, but the disadvantage is that only http/ftp is supported. if you want to change it to a chat tool, it will be difficult.
Socket cement, sand, underlying things
Fsockopen cement premade, which can be used to build a house
Curl: the gray room can be renovated by yourself.
Cement and sand can not only build houses, but also build roads, bridges, and large sculptures. The socket is also used for not only webpage transmission, but also for transmitting other things. it can be used as chat tools, downloaders, ftp ...... Almost everything that can be transmitted over the network can be written using it. of course, there is a lot of knowledge to be mastered, for example, building a wall requires you to know how to keep the wall straight, hard to fall, antifreezing, and heat insulation.
You don't need to worry about whether the premade parts are straight, how the structure is, and how they are insulated. these creators can help you think about it. what you want is to build the shape you want. Fsockopen is, you can ignore the use of creat, connect, send, recv and other functions in the socket, and open it directly.
The rough room is simpler, and you can live with decoration. The simplest way is to brush the wall. but if you want to be more comfortable, you can use more and better decoration materials. but what's the disadvantage ?? This is a house. you cannot transform it into a river crossing or a transportation purpose.
The same is true for curl. all kinds of connections are done for you, and the underlying fault tolerance processing is done. you can pass the parameter to get the desired result, but the disadvantage is that you can only use http/ftp. if you want to change it to a chat tool, it will be hard and difficult. this is really an image. thank you!