簡體   English   中英

PHP上的錯誤500 for循環

[英]Error 500 on php for loop

我正在編寫一個小腳本,該腳本從收件箱中讀取電子郵件並將其保存在mysql數據庫中。

我有一個檢查電子郵件並將其保存到數據庫的php,如果它運行了1秒鍾以上,則破壞FOR,並且我有一個ajax腳本,該腳本每次停止都會調用php。

所以這是ajax部分:

<script type="text/javascript">
$(document).ready(function(e) {
chequearCorreo(1);
});

function chequearCorreo(inicio){
$.ajax({
  type: 'POST',
  url: 'inc/a.php',
  data: {mailInicio: inicio},
   success: function(data) {
       resultado = data.split("/");
       if(resultado[0]!=resultado[1]){
           //aun no termino
           chequearCorreo(resultado[0]);
       }
       $("body").html(data);

    },
    error: function(data){

    },
 contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
 dataType: 'html'
});
}
</script>

這是PHP

session_start();
include 'coneccion-base-mails.php';

$crear_tabla_web =
'CREATE TABLE IF NOT EXISTS web  
(
id INT NOT NULL AUTO_INCREMENT,
uid int,
carpeta VARCHAR(200),
fecha DATETIME,
remitente VARCHAR(200),
destinatario VARCHAR(200),
cc VARCHAR(200),
cco VARCHAR(200),
asunto VARCHAR(200),
body TEXT,
adjuntos VARCHAR(200),
leido VARCHAR(20),
flaged VARCHAR(20),
respondido VARCHAR(20),
reenviado VARCHAR(20),
PRIMARY KEY(id)
)';
$mysqli->query($crear_tabla_web);

//FUNCION GUARDAR MAIL!!!

function guardarMail($uid,$carpeta,$fecha,$remitente,$destinatario,$cc,$cco,$asunto,$body,$leido,$flaged,$respondido,$reenviado){
global $mysqli;
//primero chequeamos que el mail no exista ya en la base
if ($result=$mysqli->query("SELECT * FROM web WHERE uid=".$uid."")){
    if( $result->num_rows == 0 ){
        //guardamos el post
        $fecha = strtotime($fecha);
        $fecha = date("Y-m-d H:i:s", $fecha);

        $cons  = "INSERT INTO web (uid,carpeta,fecha,remitente,destinatario,cc,cco,asunto) VALUES (".$uid.",'".$carpeta."','".$fecha."','".$remitente."','".$destinatario."','".$cc."','".$cco."','".$asunto."')";
        $mysqli->query($cons);
    }
}
}
//fin guardar mail

$hostname = '{localhost:143}Inbox';
$username = '##########';
$password = '###';


$tiempoInicio = microtime(true);
/* Intento de conexión */
$conn = imap_open($hostname,$username,$password) or die('No se pudo conectar con: usuario: '.$username.' y clave: '.$password.' ' . imap_last_error());

$numMsg = imap_num_msg($conn);

for($i=$mailInicio;$i<=$numMsg;$i++){

$header = imap_header($conn,$i) ;
$fromInfo = $header->from[0];
$replyInfo = $header->reply_to[0];
$toInfo = $header->to[0];
$ccInfo = $header->cc[0];
$bccInfo = $header->bcc[0]; 

$detalles = array(
    "mailRemitente" => (isset($fromInfo->mailbox) && isset($fromInfo->host))
        ? $fromInfo->mailbox . "@" . $fromInfo->host : "",
    "nombreRemitente" => (isset($fromInfo->personal))
        ? $fromInfo->personal : "",
    "mailDestinatario" => (isset($toInfo->mailbox) && isset($toInfo->host))
        ? $toInfo->mailbox . "@" . $toInfo->host : "",
    "nombreDestinatario" => (isset($toInfo->personal))
        ? $toInfo->personal : "",
    "mailRespuesta" => (isset($replyInfo->mailbox) && isset($replyInfo->host))
        ? $replyInfo->mailbox . "@" . $replyInfo->host : "",
    "nombreRespuesta" => (isset($replyTo->personal))
        ? $replyto->personal : "",
    "mailCc" => (isset($ccInfo->mailbox) && isset($ccInfo->host))
        ? $ccInfo->mailbox . "@" . $ccInfo->host : "",
    "nombreCc" => (isset($ccInfo->personal))
        ? $replyto->personal : "",
    "mailCco" => (isset($bccInfo->mailbox) && isset($bccInfo->host))
        ? $bccInfo->mailbox . "@" . $bccInfo->host : "",
    "nombreCco" => (isset($bccInfo->personal))
        ? $bccInfo->personal : "",
    "asunto" => (isset($header->subject))
        ? $header->subject : "",
    "fecha" => (isset($header->udate))
        ? $header->udate : ""
);

$uid = imap_uid($conn,$i);
guardarMail($uid,'Inbox',$detalles["fecha"],$detalles["mailRemitente"],$detalles["mailDestinatario"],$detalles["mailCc"],$detalles["mailCco"],$detalles["asunto"],'','','','','');

$tiempoActual = microtime(true);

$deltaTiempo = $tiempoActual - $tiempoInicio;


if($deltaTiempo > 1 ){


    break;

}



}
echo $i.'/'.$numMsg;

問題是該腳本運行了大約5次,但是在某個時刻ajax無法再加載php,它給出了錯誤500

托管的技術支持將php版本從5.2更改為5.3,現在可以使用了。 它有效,並且運行速度似乎更快。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM