SA-MP Forums Archive
start server in php - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: start server in php (/showthread.php?tid=261138)



start server in php - jamesbond007 - 12.06.2011

<?php
exec('cd \samp');
exec('start samp-server.exe');
echo "Server started!";
?>


nothing happens just loading forever

help will be appreciated

im running xampp apache on win


Re: start server in php - Iphone1234g - 12.06.2011

i am trying same but fail! but if u get solloution then plz post link on my page Kiss u!


Re: start server in php - Ironboy500[TW] - 12.06.2011

Try this command:

cmd /C start /D /server/dir/here /B samp-server.exe

I'm not sure about it but it should work.


Re: start server in php - jamesbond007 - 12.06.2011

^^ like how would i use that with php exactly?


Re: start server in php - Ash. - 12.06.2011

Quote:
Originally Posted by jamesbond007
Посмотреть сообщение
<?php
exec('cd \samp');
exec('start samp-server.exe');
echo "Server started!";
?>


nothing happens just loading forever

help will be appreciated

im running xampp apache on win
Is shell() and exec() active in php.ini?
I believe XAMPP/WAMP disables some features (security)


Re: start server in php - jamesbond007 - 12.06.2011

ok i figure out now i can run commands in exec on my comp .. but now when i run i get samp-server.exe not found any one knows why?

hhere is my code
Код:
<?php
  exec("cd C:\\xampp\\htdocs\\samp");
  exec("start samp-server.exe");
  echo "Server started!";
?>



Re: start server in php - jamesbond007 - 12.06.2011

bumbu,mmbumbumbumbumbumbummp anyone ??


Re: start server in php - Calgon - 12.06.2011

Because when you cd, it only changes directory for that call. Your second call for exec() doesn't recognize your use of 'cd' because it goes back to default.

Basically:
PHP код:
exec("cd /directory"); 
// cd is only remembered for the command above. It's forgotten the next time you call exec()
exec("start samp-server.exe"); // It can't find it because it doesn't remember the cd command used 
Try merging the two commands in to one call for exec().


Re: start server in php - Cyanide - 12.06.2011

You should take a look into antctrl by Westie.


Re: start server in php - Westie - 12.06.2011

Quote:
Originally Posted by Cyanide
Посмотреть сообщение
You should take a look into antctrl by Westie.
This user speaks words of goodness.

First of all, you have to start the server relative to the directory. Thus, an approach similar to IronBoy is the only way:

Код:
cmd /C start /D "\server\dir\here" /B "samp-server.exe"
Also, you'll have to start the server with a COM object.

Why, you're asking me. Well, the SA-MP process doesn't daemonise - it freezes the webpage by in effect blocking the socket, so you'll have to trick it into doing so manually. I'll give you an example from my code - well, a simplified version of it:

PHP код:
$pCOM = new COM("WScript.Shell");
$pCOM->Run('cmd /C start /D "'.addslashes(COM_RELDIR).'" /B '.COM_EXEC0false); 
Pretty much the only reliable way to do things.