php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #21764 imap_close() does not close a a stream immediately
Submitted: 2003-01-20 02:45 UTC Modified: 2017-10-24 02:05 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: mikael dot suvi at trigger dot ee Assigned: kalle (profile)
Status: Closed Package: IMAP related
PHP Version: 4.2.3 OS: Linux 2.4.18-SMP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mikael dot suvi at trigger dot ee
New email:
PHP Version: OS:

 

 [2003-01-20 02:45 UTC] mikael dot suvi at trigger dot ee
Script:
<?

$MailStream = 0;
function foo()
{
        global $MailStream;
        $ar = imap_open("{some.host/pop3:110}", "user", "pass");
        $MailStream = $ar;

        return $ar;
}

$arr = foo();
imap_close($arr);
sleep(4);
die();

?>

will not close my connection to mailserver when calling function imap_close. 
In mailserver log the following lines indicate that the stream is not closed:

Jan 20 10:28:46 mail-fe73 pop3d: LOGIN, user=suurjuht, ip=[::ffff:xxx.xxx.xxx.xxx]
Jan 20 10:28:50 mail-fe73 pop3d: LOGOUT, user=suurjuht, ip=[::ffff:xxx.xxx.xxx.xxx], top=0, retr=0

Notice the 4 second delay when user is logged out. In closes the connection when script terminates.
I guess the problem is when assigning the resource value to global variable the resources reference count is increased by one. When calling imap_close the reference value is checked and internal pop3_close is called only when reference count is 1.

c-client version is 2001

I think this behaviour is not good.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-20 02:58 UTC] derick@php.net
I think this is expected though, and I dont really consider it as a bug. Try returning the resource by reference, or not using that global. Does it work then?
 [2003-01-20 05:05 UTC] mikael dot suvi at trigger dot ee
It works if I return by refrence. 
But still, if call imap_close() I'm expecting it to close my stream.

It will make some bugs things _very hard_ to track. 
For example: if I delete a message before closing stream and  after closing I open a new stream to the same mailserver, I still get the same number of messages in my mailbox.

<?

$MailStream = 0;
function foo()
{
        global $MailStream;
        $ar1 = imap_open("{some.server/pop3:110}", "user", "pass");
        $MailStream = $ar1;

        return $ar1;
}

$arr = foo();
imap_delete($arr, 1);
imap_expunge($arr);
print imap_num_msg($arr) . " message(s) in your INBOX<br>";
imap_close($arr);

$arr1 = foo();
print imap_num_msg($arr1) . " message(s) in your INBOX";

?>

Output:
7 message(s) in your INBOX
8 message(s) in your INBOX
 [2003-08-21 03:35 UTC] mikael dot suvi at trigger dot ee
Using version php4-STABLE-200308180730
The script still produces the same results.
 [2010-12-29 17:48 UTC] jani@php.net
-Summary: IMAP: imap_close() does not close a a stream immediately +Summary: imap_close() does not close a a stream immediately -Package: Feature/Change Request +Package: IMAP related
 [2017-10-24 02:05 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2017-10-24 02:05 UTC] kalle@php.net
Please try with PHP7 and report back if this is still an issue in a new report
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC