In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what's the difference between php socket and curl". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what's the difference between php socket and curl"?
Php socket and curl differences: 1, socket is a data structure, can be used in the server and client dialogue; 2, curl is the use of url syntax to transfer files and data provisions, support many protocols, such as FTP, HTTP, TELNET and so on.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
What's the difference between php socket and curl?
The difference between curl and socket of php
First of all, what is socket:
PHP uses berkely's socket library to create his connection. Socket is a data result, and you can use this socket to open a session between the server and the client. The server is listening all the time. When a client connects to the server, he opens a port that the server is listening to to have a conversation. At this point, the server receives the connection request from the client, and a loop is made. Now the client can send information to the server, and the server can also send information to the client.
You need a total of three variables to generate a socket:
1. An agreement
2. A socket type
3. A common protocol type
The following is a detailed explanation of these three variables (I hope you can remember to chuckle)
Protocol: there are three protocols to choose from to generate a socket:
1. AF_INET is a widely used protocol for generating socket, which is transmitted using tcp or udp protocol and using ipv4 address.
2. AF_INET6 is obvious, the same as above, the difference is the use of ipv6 address
3. AF_UNIX is used on unix or Linux machines, which is rarely used, only on server-side and client-side unix or linux systems.
Socket type:
1. SOCK_STREAM is a sequential, reliable, data-complete connection based on byte stream. This is the most frequently used socket type, and this socket uses TCP for transmission.
2. SOCK_DGRAM is a connectionless, fixed-length transport call. The protocol is unreliable and uses UDP to connect to it.
3. SOCK_SEQPACKET is a dual-line, reliable connection that sends fixed-length data packets for transmission. This package must be fully accepted before it can be read.
4. SOCK_RAW is a socket type that provides a single network access, and this socket type uses the ICMP public protocol. (ping, traceroute use this protocol)
5. SOCK_RDM is rarely used and is not implemented on most operating systems. It is provided to the data link layer and does not guarantee the order of packets.
Public agreement type:
1. ICMP (Internet Control Message Protocol) Internet Control message Protocol, mainly used on gateways and hosts, to detect network status and report error messages
2. TCP (Transmission Control Protocol) transmission control protocol, which is the most widely used protocol, it can guarantee that the packet will arrive at the receiver, and if an error occurs midway, then this protocol will re-send the packet.
3. UDP (User Datagram Protocol) user packet protocol, which is connectionless and unreliable data transmission protocol.
Well, you now know that it takes three elements to generate a socke, so socket_create () in php requires three parameters, a protocol, a socket type, and a public protocol. If the creation is successful, socket_create () returns a socket resource type. If it is not successful, hey, you will receive a false.
CURL
CURL is a tool that uses URL syntax rules to transfer files and data. He supports HTTP, FTP, TELNET.
Why use cURL?
Because, if we sometimes want to have flexible access to content on a web page, such as dealing with coockies, validation, form submission, file upload, and so on. Then you need to use cURL. It is said that php has a powerful cURL library (because I don't know what the power is, so I use "said" laughter).
The basic steps for php to use cURL are as follows:
1. Initialize
2. Parameter setting
3. Page content acquisition or operation
4. Release the handle
Take a look at the following simple example.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.