Table of Contents
php中关于socket的系列函数总结,phpsocket系列函数
Home php教程 php手册 php中关于socket的系列函数总结,phpsocket系列函数

php中关于socket的系列函数总结,phpsocket系列函数

Jun 13, 2016 am 09:04 AM
php socket function

php中关于socket的系列函数总结,phpsocket系列函数

本文列举了所有关于PHP语言中使用socket相关服务的一些函数。注意使用如下函数之前,你需要确保你的socket已打开,如果你没有打开,请编辑你的php.ini文件,去掉下面这行前面的注释(分号):
复制代码 代码如下:
extension=php_sockets.dll

如果你无法去掉注释,那么请使用下面的代码来加载扩展库:
复制代码 代码如下:
if(!extension_loaded('sockets')){
 if(strtoupper(substr(PHP_OS,3))=="WIN"){
  dl('php_sockets.dll');
 }else{
  dl('sockets.so');
 }
}

如果你不知道你的socket是否打开,那么你可以使用phpinfo()函数来确定socket是否打开。你通过查看phpinfo信息了解socket是否打开。

php socket 相关函数如下:
复制代码 代码如下:
socket_accept()    接受一个Socket连接
socket_bind()     把socket绑定在一个IP地址和端口上
socket_clear_error()   清除socket的错误或者最后的错误代码
socket_close()     关闭一个socket资源
socket_connect()    开始一个socket连接
socket_create_listen()   在指定端口打开一个socket监听
socket_create_pair()   产生一对没有区别的socket到一个数组里
socket_create()    产生一个socket,相当于产生一个socket的数据结构
socket_get_option()    获取socket选项
socket_getpeername()   获取远程类似主机的ip地址
socket_getsockname()   获取本地socket的ip地址
socket_iovec_add()    添加一个新的向量到一个分散/聚合的数组
socket_iovec_alloc()   这个函数创建一个能够发送接收读写的iovec数据结构
socket_iovec_delete()   删除一个已经分配的iovec
socket_iovec_fetch()   返回指定的iovec资源的数据
socket_iovec_free()    释放一个iovec资源
socket_iovec_set()    设置iovec的数据新值
socket_last_error()    获取当前socket的最后错误代码
socket_listen()     监听由指定socket的所有连接
socket_read()     读取指定长度的数据
socket_readv()     读取从分散/聚合数组过来的数据
socket_recv()     从socket里结束数据到缓存
socket_recvfrom()    接受数据从指定的socket,如果没有指定则默认当前socket
socket_recvmsg()    从iovec里接受消息
socket_select()     多路选择
socket_send()     这个函数发送数据到已连接的socket
socket_sendmsg()    发送消息到socket
socket_sendto()    发送消息到指定地址的socket
socket_set_block()    在socket里设置为块模式
socket_set_nonblock()   socket里设置为非块模式
socket_set_option()    设置socket选项
socket_shutdown()    这个函数允许你关闭读、写、或者指定的socket
socket_strerror()    返回指定错误号的详细错误
socket_write()     写数据到socket缓存
socket_writev()    写数据到分散/聚合数组

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles