Jump to content

Having a problem running a background task


dabip

Recommended Posts

Hello, I'm trying to SSH into a remote Debian Linux Server, and run a server.

 

The server download is at: http://download.mtasa.com/deathmatch.html in case you wanted to test it out ;)

 

Anyway, here is the code I'm using:

 

My SSH Class built on top of SSH2

http://dabphp.pastebin.com/m1c5563

 

My Code utilizing it...

http://dabphp.pastebin.com/m2c0acf34

 

 

I have tried using nohup, and ./mta_server & and other things through PHP and it just won't stay running. I can run it, and keep it running in Terminal, but it just won't work in PHP. I can run things like apache(2), and other things that auto-fork into the background, just nothing that simply runs right where it's created. I hope I've included everything. This problem has been racking my brain for days now and it's just got me frustrated..

 

Anywho, thanks for taking your time to help out a frustrated 'ol php coder :P

Link to comment
Share on other sites

Hmm that didn't seem to do anything either. I'm really thinking taht it's simply the process, and not our code.

 

I even tried running a remote script on in the path of the ./mta_server file itself.

 

<?php

 

 

echo run_in_background( "./mta_server" );

 

 

$fh = fopen( 'test.txt', 'w' );

fwrite( $fh, 'Hi' );

fclose( $fh );

 

 

function run_in_background($Command, $Priority = 0)

  {

      if($Priority)

          $PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & ech$

      else

          $PID = shell_exec("nohup $Command 2> /dev/null & echo $!");

      return($PID);

  }

 

?>

 

It still failed to run into the background. :\ (I found that function on some website). It still wrote a file btw. So it was functioning correctly :\

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.