imap_ping

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_pingCheck if the IMAP stream is still active

Description

imap_ping(IMAP\Connection $imap): bool

imap_ping() pings the stream to see if it's still active. It may discover new mail; this is the preferred method for a periodic "new mail check" as well as a "keep alive" for servers which have inactivity timeout.

Parameters

imap

An IMAP\Connection instance.

Return Values

Returns true if the stream is still alive, false otherwise.

Changelog

Version Description
8.1.0 The imap parameter expects an IMAP\Connection instance now; previously, a valid imap resource was expected.

Examples

Example #1 imap_ping() Example

<?php

$imap
= imap_open("{imap.example.org}", "mailadmin", "password");

// after some sleeping
if (!imap_ping($imap)) {
// do some stuff to reconnect
}

?>

add a note add a note

User Contributed Notes 1 note

up
-18
Anonymous
21 years ago
This is a great solution for a webmail class if you want to make sure that a user is still logged in. Example:

<?php
if(!(imap_ping($stream)) {
die(
"The user is no longer logged in.");
?>
To Top