Running slowed commands trough ssh2(php)

Discussion in 'Programming/Scripts' started by ColdDoT, Nov 1, 2006.

  1. ColdDoT

    ColdDoT Member

    Hello

    i want to restart let say apache through php
    i do it with a ssh client through php, so jo get
    Code:
    sudo /etc/init.d/apache2 restart
    Problem: it wil cut of php send of commands so it wil only stop apache but not start it.

    Solution: i don't know. U?

    My toughts: run the php script, it sends the command to the system but waits 2 seconds before executing the command so that apache kan finish up the sending to the client.

    Is this clear enough?

    Greets ColdDoT
     
  2. edge

    edge Active Member Moderator

    did you try running it in quotes?

    Something like: "\sudo /etc/init.d/apache2 restart"\ or \"sudo /etc/init.d/apache2 restart\"
     
    Last edited: Nov 1, 2006
  3. ColdDoT

    ColdDoT Member

    Um wablieft

    php script
    PHP:
    function ssh($command){
        global 
    $connection$stream;
        
    $stream ssh2_exec($connection$commandFALSE);
        
    stream_set_blocking$streamtrue );
        
    $cmd fread($stream,4096);
        
    fclose($stream);
        return 
    $cmd;
    }
    $initd trim(str_replace("\n","",ssh("locate /etc/init.d/apache")));
    $reboot ssh2_exec($connectiontrim(str_replace("\n","",ssh("sudo ".$initd." restart"))), FALSE);
    The whole thing is that the command must run when my webpage is done loading
     
  4. ColdDoT

    ColdDoT Member

    Solution

    Use the
    Code:
    httpd -k graceful 
    command

    then it works

    Greets
     

Share This Page