Jezza Posted August 25, 2009 Share Posted August 25, 2009 Hey i'd like to execute a program, such as a server using PHP, BUT i need it to execute the program and not wait for it to exit? How would i do that? Running ubuntu (linux) lampp (xampp) Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 25, 2009 Share Posted August 25, 2009 I'm not sure what you mean. If you're meaning to execute an executable and output it in PHP you'd use something like this.. forgot the exact code.. $cal = @exec('cal'); echo '<pre>The date is:'; echo $cal; echo '</pre>' Quote Link to comment Share on other sites More sharing options...
Jezza Posted August 25, 2009 Author Share Posted August 25, 2009 Well if you were to exec something with php, the page would only finish loading AFTER the thing it executed stopped... I want to exec something with php, the page would load even if the thing hasn't stopped yet... Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 Then you need to put your program into the background just as you would from within the shell. system('foo &'); Quote Link to comment Share on other sites More sharing options...
Jezza Posted August 25, 2009 Author Share Posted August 25, 2009 That made absolutely no sense to me and just looking at it makes my head hurt, and it also looks like it outputs the result i don't want that, i pretty much want to simulate double clicking on a program, it opens up like that and doesn't wait for the program to finish up before it continues. Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 I don't click to run programs under Linux, a desktop is just a wrapper. Within the shell, & puts a program into the background. In my example, foo was en example program. Could just as easily have been.... exec('someprogram &'); Quote Link to comment Share on other sites More sharing options...
Jezza Posted August 25, 2009 Author Share Posted August 25, 2009 but when i do that, sure the application would start, but so long as the application is running the pages won't load, i don't want that Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 If you trying to initialize a server as you siad, you should do it through a startup script. Take a look in your /etc/init.d directory for examples if there isn't already a script written for the server you are starting. Then you would simply.... exec('/etc/init.d/nameofservice start'); and it will take care of putting the process into the background. Otherwise, the examples I have shown you should work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.