• PHP Video Tutorials

PHP - imap_timeout() Function



PHP−IMAP functions helps you to access email accounts, IMAP stands for Internet Mail Access Protocol using these functions you can also work with NNTP, POP3 protocols and local mailbox access methods.

The imap_timeout() accepts an integer value representing the time out type as a parameter and sets/fetches the time out.

Syntax

imap_timeout($timeout_type, $timeout);

Parameters

Sr.No Parameter & Description
1

timeout_type (Mandatory)

This is an integer value representing the timeout type which can be one of the following −

  • IMAP_OPENTIMEOUT

  • IMAP_READTIMEOUT

  • IMAP_WRITETIMEOUT

  • IMAP_CLOSETIMEOUT

2

timeout (Optional)

This is an integer value representing the time out values in seconds.

Return Values

This function returns a Boolean value which is TRUE in case of success and FALSE in case of a failure.

PHP Version

This function was first introduced in PHP Version 4 and works in all the later versions.

Example

Following example demonstrates the example of the imap_timeout() function −

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
         print("The current read timeout is ");
         
         $time_out = imap_timeout(IMAP_READTIMEOUT);
         print($time_out);
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

Output

This will generate the following output −

Connection established....
The current read timeout is 60

Example

You can set the time out seconds value manually as shown below −

<html>
   <body>
      <?php
         //Establishing connection
         $url = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
         $id = "tutorialspoint.test@gmail.com";
         $pwd = "cohondob_123";
         $imap = imap_open($url, $id, $pwd);
         print("Connection established...."."<br>");
         print("The current read timeout is ");
         $time = 25;
         $time_out = imap_timeout(IMAP_READTIMEOUT, $time);
         print($time_out);
         
         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

Output

This will generate the following output −

Connection established....
The current read timeout is 1
php_function_reference.htm
Advertisements