Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:49:59+00:00 2026-05-31T19:49:59+00:00

This might be a simple question, but I’m fairly new to PHP and am

  • 0

This might be a simple question, but I’m fairly new to PHP and am having a hard time figuring this out. So, a little background – my script gets called from a web based app that lets users run simple commands on remote machines. Example, the user can click a button to cat a log file on a remote machine, and it will display the output to the user. Now, if there’s a connectivity issue and ssh isn’t configured properly on the target server it can just hang forever and the ssh won’t time out. In order to display a better error to the user than the php or fastCGI timeouts, I want to kill the script and display the command the user was running before the timeouts occur. For simplicity, lets say my timeouts for IIS/FastCGI/PHP are all set to 5 minutes. I want to set a timer when the script gets kicked off, and if 4 minutes and 45 seconds have passed, I want to kill the script and display an error message to the user that displays the command they were trying to run so they can troubleshoot manually.

In stub/psuedo code for a simple example:

function StartTimer(){

//start timer 

}

function RunComand($cmd, $timer, $timeMax){

 //runs user command through ssh library and streams back output.
 $output = sshLib($cmd);

 //this is where i want to do my check on the timer. If run through ssh lib takes too long
 //kill the script and return $cmd to display it to user.

 if ($timer > $timeMax){
     //kill script, output $cmd
 }
 return $output;

}

$cmd = $_GET['cmd']  //get users command
$timer = startTimer();
$timeMax = 285; //285 seconds is 4 min 45 seconds

$results = RunCommand($cmd, $timer, $timeMax);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:50:00+00:00Added an answer on May 31, 2026 at 7:50 pm

    You could use Bunsen, “an advanced, object-oriented program execution library for PHP”.

    Here’s an example:

    <?php
    
    require 'Bunsen.class.php';
    
    // You should DEFINITELY sanatize the contents of `$_GET['cmd']` !!!
    $cmd = $_GET['cmd'];
    $timeMax = 285;
    
    $bunsen = new Bunsen;
    $bunsen->setTimeout($timeMax);
    
    $exitcode = $bunsen->exec($cmd);
    
    if ($exitcode === -1) {
        trigger_error('Maximum time limit exceeded!', E_USER_ERROR);
    }
    

    You should be VERY careful about running arbitrary commands that anyone could just put in the query string of their URL. It would be better if you had something like this:

    switch($_GET['cmd']) {
    case 1:
        $cmd = 'first command';
        break;
    case 2:
        $cmd = 'second command';
        break;
    case 3:
        $cmd = 'third command';
        break;
    default:
        trigger_error('Not allowed!', E_USER_ERROR);
    }
    

    That way they can only run known safe commands from a whitelist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a simple question, but I've had a hard time pinning down
Sorry this might be a simple question, but I could not figure it out.
I'm new to serialization, so this might be a simple question, but my google-fu
This might be a simple question but I'm just picking this up so please
This might be a simple question, but i can't seem to grasp it. I
There might be a really simple solution to this question, but i just don't
This might be simple but I am new to Oracle. I am using Oracle
This might be a simple answer, but I am having some issues writing this
This might be a simple question to answer, but I couldn't find the answer.
I think this might be a pretty simple question, but I haven't been able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.