8722 sujets

Développement web côté serveur, CMS

Bonjour.

Voilà mon problème. Je tourne en rond depuis des jours.
J'ai un message 503 au lancement d'un module de personnalisation sur un site prestashop 1.6.
Je suis hébergé chez OVH en mutualisé.
Cette après midi, j'ai pu enfin travailler normalement suite à une manipulation de OVH mais subitement, l'erreur 503 est revenue.
Je me pose la question suivante :
- un htaccess peut il solutionner le problème et si OUI comment ? OU
- le code ci-joint pose il un problème.

<?php
/**
  *  HTML5 - CSS3
  */  
/*
*/
  include(dirname(__FILE__).'/../StyleInit.php'); 
  include(dirname(__FILE__).'/../StyleConfigureClient.php');
  require_once(dirname(__FILE__)."/../StyleDirectory.php");  
  require_once(dirname(__FILE__)."/../StyleCustom.php");
  

  if (count($_FILES)>0 && isset($_COOKIE["acceptPost"]))
  { 	 
		 $array=unserialize($_COOKIE["customerLang"]);
		 $obj=new ItemStyleCustom($array['def'][0],$array['lang']);	
		 
		 $data=unserialize($_COOKIE["acceptPost"]);
		 $name=$_GET['idProduct'].'__'.$_GET['idShop'].'__'.$_GET['face'];
		 
		 if (md5(RIJNDAEL_KEY_itemStyle.$_SERVER['HTTP_USER_AGENT'].$name)==$data[0])
		 {		    
			$test=new Rijndael(RIJNDAEL_KEY_itemStyle,RIJNDAEL_ivi_itemStyle);
			$data[2]=$test->decrypt($data[2]);
			$prop=explode('__',$data[2]);	
            $general=$obj->getArrayCleProprieteFace($prop[3],'generalImage=',$_GET['idProduct'],$_GET['idShop'],$_GET['face']);
			$arr=$obj->transformListUploadAccepted($general,$_POST['type']);
           
            $komax=isset($general['komax']) ? $general['komax'] : 0 ;
            $sizeminimum=(isset($general['sizeminimum'])) ? $general['sizeminimum'] : 0; 
            $sizemaximum=(isset($general['sizemaximum'])) ? $general['sizemaximum'] : 0; 
	        $sizeminimumheight=(isset($general['sizeminimumheight'])) ? $general['sizeminimumheight'] : 0; 
            $sizemaximumheight=(isset($general['sizemaximumheight'])) ? $general['sizemaximumheight'] : 0; 
			$dpiMin=(isset($general['dpiMin'])) ? $general['dpiMin'] : 0;
			$sizeThumb=(isset($general['thumbsize'])) ? $general['thumbsize'] : '45x45' ;
			$tabThumb=explode('x',$sizeThumb);
            $acceptFormat=$arr[0];			
			$extention=$arr[2];			
 		   
		    if ($acceptFormat==true && $_POST['type']==$prop[4] && ($komax==0 || $prop[1]<=$komax*1024))
            {			  	
			  foreach ($_FILES AS $fieldName =>$file)
		      {	  
				  if ($prop[0]==1) // entier
			      {	
				    $size=@getimagesize($file['tmp_name']);
                    ItemStyleDirectory::verifySize($sizeminimum,$sizemaximum,$sizeminimumheight,$sizemaximumheight,$size);	
                    $exif=array();
					if (function_exists('exif_read_data'))
					  {                        
						$exif = @exif_read_data($file['tmp_name']);
						if ($dpiMin>0 && isset($exif['XResolution']) && isset($exif['YResolution']) && (int)$exif['XResolution']<$dpiMin)
						{
						   header("HTTP/1.1 010 upload DPI ".(int)$exif['XResolution']." ".$dpiMin);
						   exit;
						}
                      }								  
				    if (@move_uploaded_file($file['tmp_name'],dirname(__FILE__).'/'.$data[1].$extention))
					{				   
					       $ort=0;						   							  
	                       if (isset($exif['COMPUTED']['Orientation']) || isset($exif['Orientation']))
					          {							     							
					             $ort = (isset($exif['COMPUTED']['Orientation'])) ? $exif['COMPUTED']['Orientation'] : $exif['Orientation'];						
					          }
					     						
					    ItemStyleDirectory::compress_image($_POST['type'],dirname(__FILE__).'/'.$data[1].$extention, dirname(__FILE__).'/'.$data[1].$extention,100,$ort,$size,$tabThumb,dirname(__FILE__).'/thumb/'.$data[1].$extention); 					   
					    
						if ($ort>0)
                       {
						$size=@getimagesize(dirname(__FILE__).'/'.$data[1].$extention);
					   }
					    
						
					   $name=$prop[3].'__'.$data[1].$extention.'__'.str_replace("__","-",$file['name']).'__'.$prop[5].'__'.$size[0].'x'.$size[1];					   
					   $obj->savePost($name);					   
					   //$obj->insertDB('test', array('post'=> $name));
					   header( "HTTP/1.1 001 upload ".$prop[5]);
                       exit();
					}
					else
					{
					  header( "HTTP/1.1 002 upload not move_uploaded_file" );
                      exit();
					}
					
				  }
				  else
				  {				  
					if (!@move_uploaded_file($file['tmp_name'],dirname(__FILE__).'/cut/'.$data[1].'__'.$_GET['decoupe']))
					{
					  header( "HTTP/1.1 002 upload not move_uploaded_file" );
                      exit();
					}
					else 
					{
					   $dirs = @scandir(dirname(__FILE__).'/cut'); 
                       $donneeImg='';
					  
					   $cpt=0;
					   $stock=array();
					   
                       if (is_array($dirs))				
                       foreach($dirs as $file)
                       {
                           if ($file != '..' && $file != '.') 
                          {
						    $tmp=explode('__',$file);							
							if ($data[1]==$tmp[0])
							{
                              $stock[$tmp[1]]=dirname(__FILE__).'/cut/'.$file;
							}
						  }
					    }
						
						if (count($stock)==$prop[0])
						{
						   $donneeImg='';
						   foreach($stock as $val)
						   {						    
							 $donneeImg.=@file_get_contents($val);	
                             @unlink($val);							 
						   }
                            
						   //$obj->insertDB('test', array('post'=>$prop[0]));
						   $fh =@fopen(dirname(__FILE__).'/'.$data[1].$extention, 'w'); 
		                   @fwrite($fh, $donneeImg);
	                       @fclose($fh);
						   
						   $size=@getimagesize(dirname(__FILE__).'/'.$data[1].$extention);
                           ItemStyleDirectory::verifySize($sizeminimum,$sizemaximum,$sizeminimumheight,$sizemaximumheight,$size,dirname(__FILE__).'/'.$data[1].$extention);
						   
                            $exif=array();
					        if (function_exists('exif_read_data'))
					       {                        
						    $exif = exif_read_data(dirname(__FILE__).'/'.$data[1].$extention);                           							
						    if ($dpiMin>0 && isset($exif['XResolution']) && isset($exif['YResolution']) && (int)$exif['XResolution']<$dpiMin)
						    {
							  @unlink(dirname(__FILE__).'/'.$data[1].$extention);
						      header("HTTP/1.1 010 upload DPI ".(int)$exif['XResolution']." ".$dpiMin);
						      exit;
						     }
                           }							   
                            								
						   if (file_exists(dirname(__FILE__).'/'.$data[1].$extention))
						   {
						       
							   if ($prop[1]>1000000) // compress image
					           {                                     
								   @copy(dirname(__FILE__).'/'.$data[1].$extention,dirname(__FILE__).'/original/'.$data[1].$extention);
								   $ort=0;						   							  
	                               if (isset($exif['COMPUTED']['Orientation']) || isset($exif['Orientation']))
					               {							     							
					                 $ort = (isset($exif['COMPUTED']['Orientation'])) ? $exif['COMPUTED']['Orientation'] : $exif['Orientation'];						
					               }
								 
								  $valid=ItemStyleDirectory::compress_image($_POST['type'],dirname(__FILE__).'/'.$data[1].$extention, dirname(__FILE__).'/'.$data[1].$extention,80,$ort,$size,$tabThumb,dirname(__FILE__).'/thumb/'.$data[1].$extention); 					   
					              
								   if ($ort>0)
								  {
								    $size=@getimagesize(dirname(__FILE__).'/'.$data[1].$extention);
								  }
								  
								  
								  if ($valid==false)
								  {
								    @unlink(dirname(__FILE__).'/'.$data[1].$extention,dirname(__FILE__).'/original/'.$data[1].$extention);
								  }
								 }
							  
							   
							   $name=$prop[3].'__'.$data[1].$extention.'__'.str_replace("__","-",$prop[2]).'__'.$prop[5].'__'.$size[0].'x'.$size[1];							   
					           $obj->savePost($name);
							  
							  header( "HTTP/1.1 001 upload ".$prop[5] );
                              exit();
						   }
						   else
						   {
						       header( "HTTP/1.1 004 upload not cut ready");
                               exit();
						   }
						}
						else
						{
						  header( "HTTP/1.1 009 upload cut ".count($stock));
						  exit();
						}
				    }
				  }	
		      }
		    }
            else if ($acceptFormat==false)
            {
			     header( "HTTP/1.1 003 upload format" );
                 exit();
			}
           else if ($_POST['type']!=$prop[4])
            {
			     header( "HTTP/1.1 003 upload ".$_POST['type']."<>".$prop[4]);
                 exit();
			}
            else if ($prop[1]>$komax*1024)
            {
			     header( "HTTP/1.1 003 upload ".$prop[1]."<>".$komax*1024);
                 exit();
			}			
		  }
	}	  
?>

Modifié par pbpictures (21 Oct 2014 - 20:53)
Modérateur
Salut,

Une 503 c'est certainement que t'as un bug dans ton php (boucle infinie ou autre) ou alors trop de visiteurs !

Vérifie bien ton code.... Pour commencer et t'aider a cibler tu peux y aller a grand coup de copier coller pour cibler l'erreur : Tu coupe une première partie du code, tu pousse, si ça passe c'est que c'est dans l'autre partie, etc et tu coup de plus en plus fin...
Modifié par _laurent (21 Oct 2014 - 22:35)