php中的socket编程

一般不需要采集什么的话,php中不大需要直接操作socket函数的!如果是平常的采集也不需要用到socket函数。像file_get_contents这个函数就足以了。并且有些虚拟主机是关闭socket的。所以总的来说,socket在php中并不常见。但是如果你想要做一些特殊的事情,比如你采集的页面需要来路,需要cookie,或者你需要连接ftp来下载文件,那就需要socket函数了。下面就简单的介绍一下socket在php中的使用。

socket函数目录:

 

 

socket_accept -- Accepts a connection on a socket
socket_bind -- Binds a name to a socket
socket_clear_error -- Clears the error on the socket or the last error code
socket_close -- Closes a socket resource
socket_connect -- Initiates a connection on a socket
socket_create_listen -- Opens a socket on port to accept connections
socket_create_pair -- Creates a pair of indistinguishable sockets and stores them in an array
socket_create -- Create a socket (endpoint for communication)
socket_get_option -- Gets socket options for the socket
socket_getpeername --  Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type
socket_getsockname --  Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type
socket_last_error -- Returns the last error on the socket
socket_listen -- Listens for a connection on a socket
socket_read -- Reads a maximum of length bytes from a socket
socket_recv -- Receives data from a connected socket
socket_recvfrom -- Receives data from a socket, connected or not
socket_select --  Runs the select() system call on the given arrays of sockets with a specified timeout
socket_send -- Sends data to a connected socket
socket_sendto -- Sends a message to a socket, whether it is connected or not
socket_set_block --  Sets blocking mode on a socket resource
socket_set_nonblock -- Sets nonblocking mode for file descriptor fd
socket_set_option -- Sets socket options for the socket
socket_shutdown -- Shuts down a socket for receiving, sending, or both
socket_strerror -- Return a string describing a socket error
socket_write -- Write to a socket

 

 

上面列出的就是php中所有的socket函数。可能还有其它的函数,有这些就足够了。

 




[本日志由 admin 于 2011-07-19 01:08 AM 编辑]

有什么问题可以加群,100852896
点击这里加入此群 在线提问
文章来自: 本站原创
Tags: php socket socket编程
评论: 0 | 查看次数: 5465
博主QQ: 友情链接请找我
QQ群: 灰色档案
返回顶部 关闭