开发者

Control Over fopen Timeout When Opening Via FTP

I realize that there are other more straightforward ways to conduct FTP. However, I have a specific need to be able to use fopen on a file via FTP. The following code works just great:

$FTP="ftp://$FTPUser:$FTPPass开发者_Python百科@$FTPHost/$file_dest";
$fp=fopen($FTP, 'w');

The problem is when the path of the $file_dest is invalid. For example if $file_dest="1/2/3/test.txt".

If the 1, 2, or 3 folders do not exist, then it takes 90 seconds for the fopen to fail.

How can I reduce this timeout?


I would have suggested creating a stream context, but as you say, there seems to be no timeout option for the FTP protocol there.

Try whether the default_socket_timeout option as suggested here applies to FTP operations - I'm not entirely sure.

If that doesn't work out, I'm not sure whether you don't have to resort to the proper FTP functions, which definitely allow for setting a timeout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜