ftp_close() vs. ftp_quit()  
Author Message
Markus





PostPosted: 2007-5-21 19:34:50 Top

php-general, ftp_close() vs. ftp_quit() Hi

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
connection.

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!
Markus
 
purcaholic





PostPosted: 2007-5-21 19:55:00 Top

php-general >> ftp_close() vs. ftp_quit() On 21 Mai, 13:34, Markus <derernst@NO#SP#AMgmx.ch> wrote:
> Hi
>
> 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
> connection.
>
> 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!
> Markus


Hi,

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

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.

purcaholic

 
Markus





PostPosted: 2007-5-21 21:50:00 Top

php-general >> ftp_close() vs. ftp_quit() purcaholic schrieb:
> On 21 Mai, 13:34, Markus <derernst@NO#SP#AMgmx.ch> wrote:
>> Hi
>>
>> 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
>> connection.
>>
>> 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!
>> Markus
>
>
> Hi,
>
> ftp_close() and ftp_quit() do the same job, ftp_quit() is an alias of
> ftp_close().

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.)
 
 
Schraalhans Keukenmeester





PostPosted: 2007-5-21 22:51:00 Top

php-general >> ftp_close() vs. ftp_quit() At Mon, 21 May 2007 13:34:50 +0200, Markus let his monkeys type:

> Hi
>
> 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
> connection.
>
> 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!
> Markus

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():
http://nl2.php.net/manual/en/function.ftp-quit.php
http://nl2.php.net/manual/en/function.ftp-close.php

Sh.
 
 
Markus





PostPosted: 2007-5-21 23:28:00 Top

php-general >> ftp_close() vs. ftp_quit() Schraalhans Keukenmeester schrieb:
> At Mon, 21 May 2007 13:34:50 +0200, Markus let his monkeys type:
>
>> Hi
>>
>> 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
>> connection.
>>
>> 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!
>> Markus
>
> 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).

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
more.

> 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():
> http://nl2.php.net/manual/en/function.ftp-quit.php
> http://nl2.php.net/manual/en/function.ftp-close.php

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.
 
 
Kim AndrAker





PostPosted: 2007-5-21 23:35:00 Top

php-general >> ftp_close() vs. ftp_quit() Markus wrote:

> purcaholic schrieb:
> >On 21 Mai, 13:34, Markus <derernst@NO#SP#AMgmx.ch> wrote:
> > > Hi
> > >
> > > 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 connection.
> > >
> > > 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!
> > > Markus
> >
> >
> > Hi,
> >
> > ftp_close() and ftp_quit() do the same job, ftp_quit() is an alias
> > of ftp_close().
>
> 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.

Which manual have you been reading? These are the only official manual
entries for ftp_quit() and ftp_close():
http://php.net/ftp_quit
http://php.net/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).

> 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.)

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? - email***@***.com
(remove NOSPAM to contact me directly)
 
 
ED





PostPosted: 2007-5-22 17:41:00 Top

php-general >> ftp_close() vs. ftp_quit()
"Markus" <derernst@NO#SP#AMgmx.ch> wrote in message
news:46517c0c$email***@***.com...
> Hi
>
> 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
> connection.
>
> 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!
> Markus


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
connection(s):

ftp_raw($ftpconn, 'QUIT');
ftp_close($ftpconn);

cheers,
ED


 
 
Markus





PostPosted: 2007-5-22 18:26:00 Top

php-general >> ftp_close() vs. ftp_quit() ED schrieb:
> "Markus" <derernst@NO#SP#AMgmx.ch> wrote in message
> news:46517c0c$email***@***.com...
>> Hi
>>
>> 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
>> connection.
>>
>> 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!
>> Markus
>
>
> 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
> connection(s):
>
> ftp_raw($ftpconn, 'QUIT');
> ftp_close($ftpconn);

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);
}
ftp_close($ftpconn);