ftp_close() vs. ftp_quit()

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I encountered that FTP connections seem to remain open on the FTP  
server, though my FTP class has a shutdown function that ftp_quit()s the  

I did not find any info in the manual regarding the differences of  
ftp_close() and ftp_quit(). Do I have to use ftp_close()? Or even first  
close, then quit? Is it possible that ftp_quit() does not close the  
connection on the FTP server? Or do I have to look for something else?

Thanks for some hints!

Re: ftp_close() vs. ftp_quit()

Quoted text here. Click to load it


ftp_close() and ftp_quit() do the same job, ftp_quit() is an alias of

The function ftp_close() needs the connetion ressource id as parameter
to close a earlier opened connection. Maybe you call ftp_close without
a ressource id or with a wrong ressource id, this could be a reason of
remained ftp connections.


Re: ftp_close() vs. ftp_quit()

purcaholic schrieb:
Quoted text here. Click to load it

Thank you for this info. It is bad news for me, as it does contradict my  
assumptions regarding my actual problem. Anyway both functions seem to  
be wrongly documented in the manual:

void ftp_close ( resource $ftp_stream )
int ftp_quit ( int $ftp_stream )

As the signatures differ, they do not really seem to be aliases of one  
another. But actually they seem to behave the same, both not according  
to the manual: var_dump(ftp_close($conn_id)) and  
var_dump(ftp_quit($conn_id)) both display bool(true)... I filed a bug  
about this.

Anyway: Is there a possibility to find out whether a connection has been  
terminated on the FTP server side, too? (I mean, besides asking the ISP  
to give me access to log files.)

Re: ftp_close() vs. ftp_quit()

Markus wrote:

Quoted text here. Click to load it

Which manual have you been reading? These are the only official manual
entries for ftp_quit() and ftp_close():

Both should, and they do, return a boolean value (TRUE on success or
FALSE on failure) according to your own tests (and since ftp_quit() is
an alias for ftp_close(), there shouldn't be a difference, either).

Quoted text here. Click to load it

There's no way of telling, much like there's no way of telling whether
the connection to a web server was properly closed on the server side
after you've visited a website.

The only way of telling whether a connection has been terminated on the
server side, is to ask the administrator or owner of the server you're
connecting to.

Kim André Akerø
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

Re: ftp_close() vs. ftp_quit()

At Mon, 21 May 2007 13:34:50 +0200, Markus let his monkeys type:

Quoted text here. Click to load it

How exactly did you assert the connection wasn't closed after ftp_close()?
Just tried it on my localhost and my isp's server, in both cases the
connection is closed according to the vsftpd log (localhost) and the Plesk
Control Panel (isp).

Where did you find the types involved with ftp_quit()?
The dutch php manual mirrors don't give any return and parameter
type for ftp_quit():


Re: ftp_close() vs. ftp_quit()

Schraalhans Keukenmeester schrieb:
Quoted text here. Click to load it

It is a guess. I located the delays in the PHP script in the ftp login  
command, and I encountered the same delays connecting to the ftp server  
with FileZilla, and the delays occur only after the PHP script had been  
running some times. So my conclusion was that something in my script  
slows down the ftp server; I don't know much about ftp, and assumed this  
could possibly be open connections that are only closed after the  
timeout period. I will ask my ISP how to access the ftp log to find out  

Quoted text here. Click to load it

Yes I also found the correct documentations in the english version of  
the manual; the errors are in the german version. Sorry for this badly  
researched statement.

Re: ftp_close() vs. ftp_quit()

Quoted text here. Click to load it

hi Markus,

Just a thought, but maybe try sending an FTP QUIT command to the server  
before closing the conn - it may give the server the hint to close its  

ftp_raw($ftpconn, 'QUIT');


Re: ftp_close() vs. ftp_quit()

ED schrieb:
Quoted text here. Click to load it

Thank you, good point! As ftp_raw() is PHP5 only and the application is  
supposed to run from PHP 4.3 upwards, I added reduction of the timeout  
period, so the number of possibly open connections on the server should  
be reduced to a reasonable amount:

if (function_exists('ftp_raw')) {
   ftp_raw($ftpconn, 'QUIT');
else {
   ftp_set_option($ftpconn, FTP_TIMEOUT_SEC, 1);

Site Timeline