php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18646 ftp_close not working properly
Submitted: 2002-07-30 09:04 UTC Modified: 2002-07-30 16:51 UTC
From: nohn@php.net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4CVS-2002-07-30 OS: Compaq Tru64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nohn@php.net
New email:
PHP Version: OS:

 

 [2002-07-30 09:04 UTC] nohn@php.net
Following script seems to work not properly, but maybe I've simply misunderstood the documentation:

<?php
  $ftp_server = "2.14.128.38";

  $ftp = ftp_connect("$ftp_server");
  echo("FTP: "); var_dump($ftp); echo("\n");

  if (ftp_close($ftp)) {
    $result = 1;
  } else {
    $result = 0;
  }

  echo "Result: $result\n";
?>

> ~/php4-200207292100_install/bin/php tests/ftp/ftp_close.php
Unaligned access pid=6597 <php> va=0x140064c8c pc=0x1201ba050 ra=0x1201ba044 inst=0xb4010000

FTP: resource(4) of type (FTP Buffer)

Result: 0

So there seems a ftp-resource (well the documentation still says, ftp_connect would return a boolean value) that seems not to be valid to ftp_close.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-30 09:13 UTC] nohn@php.net
same thing with ftp_quit. Other ftp-functions using the result resource seem to work
 [2002-07-30 09:48 UTC] msopacua at idg dot nl
Not a bug on the result issue.
void <<< ftp_close.

void returns NULL, which resolves to FALSE.

Could you var_dump($ftp) instead of echoing $result, to see if the resource was freed?
 [2002-07-30 09:59 UTC] nohn@php.net
I hope, this is what you were asking for:

<?php 
  $ftp_server = "2.14.128.38"; 

  $ftp = ftp_connect("$ftp_server"); 
  echo("FTP: "); var_dump($ftp); echo("\n"); 

  ftp_close($ftp);
  var_dump($ftp);

?>

results in this:

Unaligned access pid=19673 <php> va=0x140064c8c pc=0x1201ba050 ra=0x1201ba044 inst=0xb4010000
FTP: resource(4) of type (FTP Buffer)

resource(4) of type (Unknown)
 [2002-07-30 09:59 UTC] kalowsky@php.net
marking as feedback until Sebastian responds. 
 [2002-07-30 11:44 UTC] msopacua at idg dot nl
Sebas,

is the unaligned access issue, part of this problem, or a larger one? Because the ftp_close issue, is expected behaviour:
$ cat test.php
<?php
include('pass.php');
$cs = mysql_connect('localhost:/sql/tmp/mysql.sock', $user, $password);
var_dump($cs);

mysql_close($cs);
var_dump($cs);

$fp = fopen('file.txt', 'w');
var_dump($fp);

fclose($fp);
var_dump($fp);

$ftp = ftp_connect($ftp_server);
var_dump($ftp);

ftp_close($ftp);
var_dump($ftp);

?>
--OUTPUT--
$ !php
php -f test.php 
resource(5) of type (mysql link)
resource(5) of type (Unknown)
resource(6) of type (stream)
resource(6) of type (Unknown)
resource(7) of type (FTP Buffer)
resource(7) of type (Unknown)

Kindof disturbing that the type remains resource, but it has never bothered me IRL :-)
 [2002-07-30 12:03 UTC] nohn@php.net
Yes well... But the most important thing is this:

  if (ftp_close($ftp)) { 
    $result = 1; 
  } else { 
    $result = 0; 
  } 

result is 0 in this case as described below which means that ftp_close returns false even on success. So how to check if the connection was closed?

The unaligned access thing happens since... I don't remember when, but see bugs 18588, 18288, 18623, 17449 for some examples.
 [2002-07-30 12:11 UTC] msopacua at idg dot nl
It's a void function, returning nothing. And nothing == FALSE.
Make the last bit:
if(ftp_close($ftp) === FALSE)
{
        $result=0;
}
else
{
        $result=1;
}
var_dump($ftp);

var_dump($result);

---OUTPUT---
resource(5) of type (mysql link)
resource(5) of type (Unknown)
resource(6) of type (stream)
resource(6) of type (Unknown)
resource(7) of type (FTP Buffer)
resource(7) of type (Unknown)
int(1)

Than change it to:
if(ftp_close($ftp) === NULL)
 [2002-07-30 12:44 UTC] msopacua at idg dot nl
Whether it should remain a void function is a feature request.

Maybe it should be changed like below, but that's up to Andrew and Stefan.
Index: php_ftp.c
===================================================================
RCS file: /repository/php4/ext/ftp/php_ftp.c,v
retrieving revision 1.65
diff -u -r1.65 php_ftp.c
--- php_ftp.c   26 Jul 2002 22:00:25 -0000      1.65
+++ php_ftp.c   30 Jul 2002 16:41:50 -0000
@@ -1021,7 +1021,10 @@

        ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);

-       zend_list_delete(Z_LVAL_P(z_ftp));
+       if(zend_list_delete(Z_LVAL_P(z_ftp)) != SUCCESS)
+       {
+               php_error(E_NOTICE, "Could not close ftp stream");
+       }
 }
 /* }}} */
 [2002-07-30 14:22 UTC] nohn@php.net
Yes. It would be great to make this a feature like mysql_close that also returns TRUE if it succeded or FALSE if it failed.
 [2002-07-30 16:49 UTC] kalowsky@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 [2002-07-30 16:51 UTC] sesser@php.net
fixed in HEAD. ftp_quit/close return now TRUE or FALSE.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Jun 16 09:00:02 2026 UTC