入门指引 Server Client Process AsyncIO Memory HttpServer WebSocket 高级 其他

发布于 2015-08-09 09:45:57 | 92 次阅读 | 评论: 0 | 来源: 网络整理

发送文件到TCP客户端连接。使用示例:

bool swoole_server->sendfile(int $fd, string $filename);
$serv->sendfile($fd, __DIR__.'/test.jpg');

sendfile函数调用OS提供的sendfile系统调用,由操作系统直接读取文件并写入socket。sendfile只有2次内存拷贝,使用此函数可以降低发送大量文件时操作系统的CPU和内存占用。

  • $filename 要发送的文件路径,如果文件不存在会返回false
  • 操作成功返回true,失败返回false

此函数与swoole_server->send都是向客户端发送数据,不同的是sendfile的数据来自于指定的文件。

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务