首页 > 解决方案 > PHP 页面中途停止加载 - 未完成代码

问题描述

我有一个网络应用程序,我可以在其中查看我的 Gmail 帐户收件箱中的所有邮件,并搜索特定字符串以挑选不同的电子邮件。

在这个应用程序上,我可以设置要搜索的电子邮件数量的限制。如果我将此限制设置为“200”或更低,它在大多数情况下都可以正常工作。但是,如果我将限制增加到 400 及以上,则 99% 的时间,应用程序/页面会停止加载。并且代码没有完成。

我已启用,因此 PHP 通过主机网站以及每个 php 页面开头的代码显示错误消息:

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
?>

但是,当页面停止加载时,不会显示任何错误消息。(它确实显示在其他错误上)

这是我正在使用的代码,以及 Gmail API。

<?php
//Authentication with Gmail API happens here
$gmail = new Google_Service_Gmail($client);
$number_of_emails_to_fetch = 500; 
$list = $gmail->users_messages->listUsersMessages('me', ['maxResults' => $number_of_emails_to_fetch]);


$filename = "unsubscribe-show-all.php";
$sql_table_name = create_table();
$connection = open_connection();
while ($list->getMessages() != null) {

    foreach ($list->getMessages() as $mlist) {

        $message_id = $mlist->id;
        $optParamsGet2['format'] = 'full';
        $single_message = $gmail->users_messages->get('me', $message_id, $optParamsGet2);
        $payload = $single_message->getPayload();
        $parts = $payload->getParts();
        // With no attachment, the payload might be directly in the body, encoded.
        $body = $payload->getBody();
        $FOUND_BODY = FALSE;
        // If we didn't find a body, let's look for the parts
        if(!$FOUND_BODY) {
            foreach ($parts  as $part) {
                if($part['parts'] && !$FOUND_BODY) {
                    foreach ($part['parts'] as $p) {
                        if($p['parts'] && count($p['parts']) > 0){
                            foreach ($p['parts'] as $y) {
                                if(($y['mimeType'] === 'text/html') && $y['body']) {
                                    $FOUND_BODY = decodeBody($y['body']->data);
                                    break;
                                }
                            }
                        } else if(($p['mimeType'] === 'text/html') && $p['body']) {
                            $FOUND_BODY = decodeBody($p['body']->data);
                            break;
                        }
                    }
                }
                if($FOUND_BODY) {
                    break;
                }
            }
        }
       
        // If we didn't find the body in the last parts, 
        // let's loop for the first parts (text-html only)
        if(!$FOUND_BODY) {
            foreach ($parts  as $part) {
                if($part['body'] && $part['mimeType'] === 'text/html') {
                    $FOUND_BODY = decodeBody($part['body']->data);
                    break;
                }
            }
        }
        // With no attachment, the payload might be directly in the body, encoded.
        if(!$FOUND_BODY) {
            $FOUND_BODY = decodeBody($body['data']);
        }
        if(!$FOUND_BODY) {
            $FOUND_BODY = '(No message)';
        }
}
?>

在这段代码之后,我有更多的代码可以处理将不同的链接插入数据库,然后进行重定向。但是,我尝试删除该代码并仅运行上面的代码+重定向,但页面仍然停止加载,所以我认为它与这个片段有关。

任何有关在哪里阅读的建议或有关如何解决此问题的提示将不胜感激!

标签: phpgmail-api

解决方案


推荐阅读