IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

Débogage pour une fonction prenant trop de temps


Sujet :

Symfony PHP

  1. #1
    Membre éclairé Avatar de fahdijbeli
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juin 2012
    Messages : 281
    Par défaut Débogage pour une fonction prenant trop de temps
    bonjour,
    l'orsque je teste ma route il affiche cette erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\voip2\src\Customers\CustomersToolsBundle\Service\JSON_RPC_Client.php on line 50
    je veux débuger ma route comment, et merci d'avance.

  2. #2
    Membre éclairé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2012
    Messages
    394
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2012
    Messages : 394
    Par défaut
    Essaye cette commande :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    php app/console router:debug
    Et tu verra si la route existe ou pas !

  3. #3
    Membre éclairé Avatar de fahdijbeli
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juin 2012
    Messages : 281
    Par défaut
    bonjour,
    je veux pas verfier m route existe ou pas .dans mon application j'ai crée une classe qui va appeler un service web chez un serveur situé dans la france
    le probléme que j'attend beaucoup la réponse qui est l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\voip2\src\Customers\CustomersToolsBundle\Service\JSON_RPC_Client.php on line 50
    voici mon classe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
     
    <?php
    namespace Customers\CustomersToolsBundle\Service; 
    use \stdClass;
     
    class JSON_RPC_Client  {
    	private $auth;
    	private $url;
    	private $curl = NULL;
     
    	function __construct($url) {
    		$this->url = $url;
    	}
     
    	public function set_auth_credentials($login, $password) {
    		$this->auth = "{$login}:{$password}";
    	}
     
    	public function call() {
    		$params = func_get_args();
    		$method = array_shift($params);
    		$request = $this->_create_request($method, $params);
    		$data = $this->_send_request($request);
    		$response = $this->_parse_response($data, $error);
    		if ($error) {
    			throw new Exception('JSON-RPC error: '.$response->message, $response->code); // use custom Exception
    		}
    		return $response;
    	}
     
    	/* private methods */
    	private function _send_request($request) {
    		if ($this->curl !== NULL) {
    			curl_close($this->curl);
    		}
    		$this->curl =curl_init($this->url);
    		$headers = array(
    			'Expect:', // avoid lighttpd bug
    			'Content-Type: application/json-rpc; charset=utf-8',
    		);
    		curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
    		curl_setopt($this->curl, CURLOPT_FORBID_REUSE, TRUE);
    		curl_setopt($this->curl, CURLOPT_FRESH_CONNECT, TRUE);
    		curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
    		curl_setopt($this->curl, CURLOPT_POST, TRUE);
    		curl_setopt($this->curl, CURLOPT_POSTFIELDS, json_encode($request));
    		curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    		if (!empty($this->auth)) {
    			curl_setopt($this->curl, CURLOPT_USERPWD, $this->auth);
    		}
    		$data = curl_exec($this->curl);
    		if ($data === FALSE) {
    			error_log("[".curl_errno($this->curl)."] ".curl_error($this->curl));
    		}
    		return $data;
    	}
     
    	private function _create_request($method, $params) {
    		$request = new stdClass;
    		$request->id = 42; // or use a random id
    		$request->jsonrpc = '2.0';
    		$request->method = $method;
    		$request->params = $params;
    		return $request;
    	}
     
    	private function _parse_response($data, &$error) {
    		if ($data === FALSE) {
    			throw new Exception('cURL error ['.curl_errno($this->curl).'] '.curl_error($this->curl));
    		}
    		$data = json_decode($data);
    		if (!is_object($data)) {
    			throw new Exception('Parse error: result is not an object.');
    		}
    		if (!property_exists($data, 'result') && !property_exists($data, 'error')) {
    			throw new Exception('Parse error: missing property');
    		}
    		if (property_exists($data, 'error')) {
    			$error = TRUE;
    			return $data->error;
    		}
    		return $data->result;
    	}
    }
    ?>
    et merci .

  4. #4
    Membre éprouvé Avatar de Avrel
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2010
    Messages : 118
    Par défaut
    Tu peux nous montrer la stack trace de ton erreur ?

  5. #5
    Membre éclairé Avatar de fahdijbeli
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juin 2012
    Messages : 281
    Par défaut
    bonjour,
    j'ai pas une idée comment je montre la stack

  6. #6
    Membre Expert
    Avatar de gene69
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    1 769
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Janvier 2006
    Messages : 1 769
    Par défaut
    la stack ne dira pas grand chose dans ce cas, sauf qu'il y a une boucle ou une récurssion qui prend du temps et ce qu'on verra n'est pas très parlant parce le dessus de la pile ne sera pas forcement la boucle elle-même ni la fonction coupable.

    la premiere chose a faire et d'augmenter (*2 *3) le temps d'exec autorisé. ça corrige pas le problème mais si ton traitement flirte avec les 30 secondes alors ça décoince ponctuellement.

    ensuite, ben c'est le caca:
    - optimisation avec outil de profilage
    https://www.google.fr/webhp#q=profiling+php
    http://talks.php.net/show/perf_tunning
    - précalcul & abandon des calculs à la volée.
    - achat d'un serveur plus puissant (+ de mémoires, + de processeurs )

  7. #7
    Membre Expert
    Avatar de gene69
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    1 769
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Janvier 2006
    Messages : 1 769
    Par défaut
    regarde ci ceci t'aide, je sais pas si le timeout est catché par le
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    <?php
     
    ini_set('max_execution_time',5);
     
    function showerror($error ){
    	debug_print_backtrace();
    	var_dump($error);
    }
     
    function loopingfunc(){
       while( true ){
          reallongfunc();
       }
    }
     
    function reallongfunc(){
    		sleep(1); //
    }
     
    set_exception_handler( 'showerror' );
    set_error_handler('showerror');
     
    loopingfunc();
    moi j'ai xdebug sur mon php du coup je vois ma stack à chaque fois.

  8. #8
    Membre éclairé Avatar de fahdijbeli
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2012
    Messages
    281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Juin 2012
    Messages : 281
    Par défaut
    merci, j'essaye de le faire

Discussions similaires

  1. Réponses: 15
    Dernier message: 26/03/2006, 12h10
  2. Aide pour une fonction
    Par mimi060101 dans le forum Scheme
    Réponses: 1
    Dernier message: 24/02/2006, 16h59
  3. [Tableaux] demande de code pour une fonction.php
    Par carmen256 dans le forum Langage
    Réponses: 4
    Dernier message: 21/01/2006, 17h22
  4. [FLASH MX] nom variable pour une fonction
    Par totoche dans le forum Flash
    Réponses: 2
    Dernier message: 20/12/2005, 14h00
  5. paramètres pour une fonction
    Par bul dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 28/05/2005, 07h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo