Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/05/2010, 07:38
Avatar de Nekeniehl
Nekeniehl
 
Fecha de Ingreso: julio-2009
Ubicación: Berlin, Alemania / Granada, España
Mensajes: 132
Antigüedad: 14 años, 8 meses
Puntos: 6
Optimización de codigo php

Buenas compañeros, buscaba la manera de poder optimizar al máximo el siguiente script, y de paso preguntaros que reglas/truquitos tenéis para poder optimizar los vuestros?
Código PHP:
<?php
include ('config.cron.php');
include (
'/libs/php/class.queue.php');
echo 
'<pre>';
$queue=new Queue();

//Opening new document
$handle fopen(_PROJECTS_DIR."/temp/cron-queue-".date("Y-m-d").'.log'"a+");
fwrite($handle"\n =================== START ===================== ".date("Y-m-d H:i")."\n");
fflush($handle);

//Checking the server status and queue storage
$serverOn=$queue->checkServer()?true:false;
$queueEmpty=$queue->checkIsEmpty()?true:false;

$send=$serverOn?$queueEmpty?false:true:false;

$msg=$serverOn?"Server OK...":"Server OK...";
$msg.=$queueEmpty?"Queue Empty\n":"Queue have msg\n";
if(
$send){
    
$sql "SELECT count(idQueue) FROM MsgQueue";
    
$cont$db->GetOne($sql);
    
//Looping for all msg from the queue
    
for ($i=1;$i<=$cont;$i++){
        
$fifo=$queue->getMsg($queue->fifo());
        
//Preparing the line of the msg
        
$msg="MSG ID".$fifo['idQueue']."\n"."MSG REQUEST:".$fifo['request']."\n\n";
        
//Checking if the resend function has been successful 
        
$msg.=$queue->resendMsg()?"Send...Successful":"\n\nSend...Unsuccessful!\n";
        
fwrite($handle,$msg);
        
fflush($handle);
    }    
}
else{
    
fwrite ($handle$msg);
}
fwrite($handle"\n =================== FINISH ===================== ".date("Y-m-d H:i")."\n");
fflush($handle);
fclose($handle);    
?>
El script comprueba que el server está on y que hay mensajes en la cola y procede a mandarlos.
Un saludo