PHP - imap_gc() 函式



PHP−IMAP 函式可以幫助您訪問電子郵件帳戶,IMAP 代表 **I**nternet **M**ail **A**ccess **P**rotocol,使用這些函式您還可以處理 NNTP、POP3 協議和本地郵箱訪問方法。

**imap_gc()** 函式接受一個表示 IMAP 流的資源值,一個表示快取的整數,並清除/清空指定的快取。

語法

imap_gc($imap_stream, $chaches);

引數

序號 引數及描述
1

imap_stream (必填)

這是一個表示 IMAP 流的字串值,是 **imap_open()** 函式的返回值。

2

caches (必填)

這是一個表示要清除的快取的整數。它可以是以下常量的組合:IMAP_GC_ELT(訊息快取元素)、IMAP_GC_ENV(信封和正文)、IMAP_GC_TEXTS(文字)。

返回值

此函式返回一個布林值,成功時為 TRUE,失敗時為 FALSE。

PHP 版本

此函式首次在 PHP 5 版本中引入,並在所有後續版本中有效。

示例

以下示例演示了 **imap_gc()** 函式的使用 −

<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>");
         //Clearing the cache
         $res = imap_gc($imap, IMAP_GC_TEXTS);
         
         if($res){
            print("Cache Cleared");
         }else{
            print("Error Occurred");
         }
		   //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 −

Connection established....
Cache Cleared

示例

以下示例清除有關信封和正文的快取 −

<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>");
         //Clearing the cache
         $res = imap_gc($imap, IMAP_GC_ENV);         

         //Closing the connection
         imap_close($imap);   
      ?>
   </body>
</html>

輸出

這將生成以下輸出 −

Connection established....
php_function_reference.htm
廣告