百科狗-知识改变命运!
--

ftp_nb_put() - ftp函数

梵高12个月前 (11-21)阅读数 9#技术干货
文章标签的是

ftp_nb_put()

(PHP 4 >= 4.3.0, PHP 5, PHP 7)

存储一个文件至 FTP 服务器(non-blocking)

说明

ftp_nb_put(resource $ftp_stream,string $remote_file,string $local_file,int $mode[,int $startpos]): int

ftp_nb_put() - ftp函数

ftp_nb_put()函数用来把本地文件$local_file存储到 FTP 服务器上由$remote_file参数指定的路径。传输模式参数$mode只能为FTP_ASCII(文本模式)或FTP_BINARY(二进制模式)两种。与函数ftp_put()不同的是,此函数上传文件的时候采用的是异步传输模式,也就意味着在文件传送的过程中,你的程序可以继续干其它的事情。

返回FTP_FAILEDFTP_FINISHEDFTP_MOREDATA

ftp_nb_put()实例

使用ftp_nb_put()来断线续传

参见ftp_nb_fput(),ftp_nb_continue(),ftp_put()和ftp_fput()。

When using non blocking functions if you try to disconnect while your non blocking operation is in progress the disconnect command will not work until the operation is not finished.
Don't add a sleep() inside the loop. If you do you will severely slow down the upload.
In my tests, each time through the loop it send about 2.5K, looping about 220 times per second. (Which is very little.)
You won't necessarily get the same numbers as me per loop, but clearly PHP does it's own management of the loop so that you don't consume all the CPU on the server.
If you receive an error like: 
Warning: ftp_nb_put(): Unable to service PORT commands in /path/to/file.php on line 27
verify whether you need to be in PASV mode. You can go into PASV mode by declaring
> ftp_pasv($cnx,TRUE);
How to realize the possibility of transferring data from one FTP-server to another via FXP: 
I couldn't see this noted anywhere...
ftp_nb_put apparently takes a much much longer time to upload the file than ftp_put (I haven't done any packet sniffing or logging tests to find out why). I was using a script, nearly identical to the example above, and a 100KB file had only uploaded 3.99KB after about 8 minutes! The php script naturally timed out before it was complete.
I changed my function to use ftp_put, got rid of the loop to check FTP_MOREDATA (as you will see in the example above), and the same script uploaded 2.2MB within 30 seconds with no other changes.
If you're using this function instead of ftp_put *purely to try to speed up your script* and it's taking a long time, you might want to try ftp_put instead.
Hi Everybody,
ftp_put not working in client server, but it working properly on my local system.
Issue on client server:
Production.ERROR: ftp_put(): I won't open a connection to 172.31.17.181 (only to 52.33.186.63).
My script upload a file from local system to remote server.
Thanks
Paras Chauhan
Hi, 
I tried to use both ftp_put() and ftp_nb_put() adding the
variable $start = date("Y:m:d h:i:s"); at the begin of the script and the variable $end = date("Y:m:d h:i:s"); at its end, after the file upload function.
With the gprs connection I'm now using and trying to upload a .jpg file of 67,5 kb the time difference between $start and $end was 40 seconds in both cases, so I can suppose that there is no difference between these upload function.
The difference comes if you put anything inside the while ($ftp_upload == FTP_MOREDATA) loop.
I hope this note can help.
Regards
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)