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

PHP & Base de données Discussion :

PHP ssh2_exec Streams


Sujet :

PHP & Base de données

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2019
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2019
    Messages : 2
    Par défaut PHP ssh2_exec Streams
    Hi everyone,

    I've been working on a project which connect through SSH to make a certain command and then get the output, this needs to be 3 times to get 3 differents informations which i get from SNMP.

    I have tested my command, and manually they all work.

    It all works for the first loop, i am able to get the data out of the command, sadly for the 2 others in the loop they are empty, it's like no value has been attached to the variable.

    But I tested that when I change $ServerCommandRadioSignal to $ServerCommandRadioModel i get the same data as the first loop when $i == 0..

    I am out of options, I have try unsetting streams or closing the variables SSH2_Exec, but none work.. Does someone have an idea?


    for($i = 0; $i < 3; $i++) {
    //echo $i;
    if($i == 0) {
    $stream0 = ssh2_exec($sshconn, $ServerCommandRadioModel);
    stream_set_blocking($stream0, true);
    $stream0_out = ssh2_fetch_stream($stream0, SSH2_STREAM_STDIO);
    $UserRadioModel = stream_get_contents($stream0_out);
    echo $UserRadioModel;
    fclose($stream0);
    fclose($stream0_out);
    }

    if($i == 1) {
    $stream1 = ssh2_exec($sshconn, $ServerCommandRadioSignal);
    stream_set_blocking($stream1, true);
    $stream1_out = ssh2_fetch_stream($stream1, SSH2_STREAM_STDIO);
    $UserRadioSignal = stream_get_contents($stream1_out);
    echo $UserRadioSignal;
    fclose($stream1);
    fclose($stream1_out);
    }

    if($i == 2) {
    $stream2 = ssh2_exec($sshconn, $ServerCommandRadioSSID);
    stream_set_blocking($stream2, true);
    $stream2_out = ssh2_fetch_stream($stream2, SSH2_STREAM_STDIO);
    $UserRadioSSID = stream_get_contents($stream2_out);
    echo $UserRadioSSID;
    fclose($stream2);
    fclose($stream2_out);
    }

    }



    When the script runs these are the outcome.

    1st Loop = "somedata1"
    2nd Loop = nothing
    3rd Loop = nothing

  2. #2
    Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Janvier 2019
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2019
    Messages : 2
    Par défaut
    Please close this ticket, I have found the solution:

    $ServerCommands = [$ServerCommandRadioModel, $ServerCommandRadioSignal, $ServerCommandRadioSSID];
    $UserRadioOutput = [];
    $i = 0;

    foreach($ServerCommands as $ServerUniqueCommand) {
    $stream = ssh2_exec($sshconn, $ServerUniqueCommand);
    stream_set_blocking($stream, true);
    $stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);

    if($i == 0) {
    $UserRadioOutput[0] = stream_get_contents($stream_out);
    echo $UserRadioOutput[0];
    } elseif($i == 1) {
    $UserRadioOutput[1] = stream_get_contents($stream_out);
    echo $UserRadioOutput[1];
    } elseif($i == 2) {
    $UserRadioOutput[2] = stream_get_contents($stream_out);
    echo $UserRadioOutput[2];
    }
    //echo $i;
    $i++;
    }


    ssh2_exec($sshconn, 'exit');
    unset($sshconn);

Discussions similaires

  1. Php Tweet Stream
    Par ezz_amine dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 24/04/2013, 21h29
  2. [PHP-JS] streaming vlc et php
    Par sneb5757 dans le forum Langage
    Réponses: 9
    Dernier message: 11/04/2012, 12h01
  3. PHP et Streaming
    Par madislak dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 01/01/2007, 14h23
  4. Quel hébergeur choisir pour du Streaming Vidéo (PHP) ?
    Par wehtam dans le forum Hébergement
    Réponses: 6
    Dernier message: 28/08/2006, 16h16
  5. [Forum] Streaming et PHP
    Par wehtam dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 4
    Dernier message: 09/08/2006, 15h54

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