Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Wywoływanie zewnętrznych poleceń - Problem
cabana
post
Post #1





Grupa: Zarejestrowani
Postów: 88
Pomógł: 0
Dołączył: 25.05.2010

Ostrzeżenie: (0%)
-----


Witam.
Mam problem ze skryptem który będzie uruchamiał serwer z rzędu www.
Próbowałem zrobić to przez system oraz exec ale żaden z tych sposobów nie zadziałał.
Proszę o pomoc przy rozwiązaniu tego problemu. (IMG:style_emoticons/default/sadsmiley02.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
cabana
post
Post #2





Grupa: Zarejestrowani
Postów: 88
Pomógł: 0
Dołączył: 25.05.2010

Ostrzeżenie: (0%)
-----


@mls

Twój sposób zadziałał świetnie. (IMG:style_emoticons/default/smile.gif)
Teraz pozostała mi tylko kwestia pobrania pid uruchomionego procesu. Macie może jakieś sposoby? doradźcie jak tego dokonać.
Nie oczekuje od was gotowca tylko rady jakich funkcji lub czegoś użyć.

A więc po przeczytaniu wielu poradników i manuali napisałem coś takiego:

  1. <?php
  2. include('lib/config.php');
  3. $config['serwer_path'] = '/home/shoutcast/sc_'.$_SESSION['userID'];
  4. $config['serwer_filename'] = 'sc_serv_'.$_SESSION['userID'];
  5. $config['serwer_fileconfig'] = 'sc_serv.conf';
  6.  
  7. if ($_GET['action'] == 'start')
  8. {
  9. $serwer = @fsockopen($config['ip'], $serwer['port'], $errno, $errstr, 1);
  10. if (!$serwer)
  11. {
  12. @exec($config['serwer_path']."".$config['serwer_filename']." ".$config['serwer_path']."".$config['serwer_fileconfig']." >/dev/null &");
  13. $GLOBALS['template']['content'] = 'Serwer został uruchomiony.';
  14. }
  15. else
  16. {
  17. $GLOBALS['template']['content'] = 'Serwer już jest uruchomiony.';
  18. }
  19. }
  20. else if ($_GET['action'] == 'stop')
  21. {
  22. $serwer = @fsockopen($config['ip'], $serwer['port'], $errno, $errstr, 1);
  23. if ($serwer)
  24. {
  25. $pid = @exec("pgrep -x ".$config['serwer_filename']);
  26. @exec("kill -9 $pid");
  27. $GLOBALS['template']['content'] = 'Serwer został wyłączony.';
  28. }
  29. else
  30. {
  31. $GLOBALS['template']['content'] = 'Serwer nie jest uruchomiony.';
  32. }
  33. }
  34. else if ($_GET['action'] == 'restart')
  35. {
  36. $serwer = @fsockopen($config['ip'], $serwer['port'], $errno, $errstr, 1);
  37. if ($serwer)
  38. {
  39. $pid = @exec("pgrep -x ".$config['serwer_filename']);
  40. @exec("kill -9 $pid");
  41. @exec($config['serwer_path']."".$config['serwer_filename']." ".$config['serwer_path']."".$config['serwer_fileconfig']." >/dev/null &");
  42. $GLOBALS['template']['content'] = 'Serwer został zrestartowany.';
  43. }
  44. else
  45. {
  46. $GLOBALS['template']['content'] = 'Serwer nie jest uruchomiony.';
  47. }
  48. }
  49. else
  50. {
  51. $GLOBALS['template']['content'] = 'Nie rozpoznałem komendy.';
  52. }
  53.  
  54. include('template.php');
  55. ?>


Mój problem został już rozwiązany. Kod daje aby ktoś na przyszłość nie pisał podobnego tematu tylko żeby mógł zobaczyć jak to się robi.
Dziękuje wszystkim za pomoc i zaangażowanie (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 18:18