Localhost:8000 keeps working after installing laravel-angular boilerplate project - php

I installed laravel-angular project according to its documentation.
I run php artisan serve command which is supposed to run the server. That is what happened.
But then I wanted to kill this server because I think it messed up with my existing apache configuration. And I found it problematic because there is no command for killing it. All the resource in the internet says that all you have to do is to CTRL + C to kill the process but I don't have it opened in my console any more.
It runs even after restarting my computer.
I removed the project sources from my disk hoping it will help. It didn't
Then I thought that probably artisan is running internal PHP dev server. I searched for it but this server also does not have any shutdown command - All you have to do is to CTRL + C the proccess in console. It didn't help.
Okay so I though I will look for process id somewhere - using netstat or task manager in windows. I did not find anything listening on :8000 port or any process that can be responsible for serving it.
Last try I had was to manually run php -s localhost:8000 - seems like it succeded to start. I added some file to current directory and I was able to run it through localhost:8000/filename.php
However when I killed it (I see this process everywhere - in task manager, in netstat etc), localhost:8000/filename.php does not work anymore but localhost:8000 (which is then redirected to localhost:8000/#/) still works.
It looks like it's not the server running but some redirection is added to my machine.
I would like to resolve the problem - get rid of this and have my apache working as expected.

It's because laravel-angular has service worker. Check in Network tab in Chrome shows that response for network requests came from service worker.
You may read more about them here - http://www.html5rocks.com/en/tutorials/service-worker/introduction/

Related

Managing some NodeJS script from outside

I have some NodeJS scripts, that runs 24/7 on a windows vServer. Normally I connect via RDM/VNC, open a console, navigate to the path of the script and type in "node ." to start it.
Sometimes I need to check the output of that scripts and sometimes I want to restart them.
Then I connect again to the server, check the shell, abort the process and restart it with "node ." again.
But now I want some other people to do that too but I dont want to give them access to my server.
So my plan was to do a "Managing website".
But atm I have no idea how to do it. I have several problems: First, How can I start the script with "node ." in php? I tried several stuff with the exec and shell_exec command. One example:
echo shell_exec('cd C:\\Users\***\\');
echo shell_exec("node .");
But I dont even get an output back. So obviously there is something wrong.
Second, every user of that website should see the same output. If someone hits the "Restart" Button (need to figure out a way how to restart it too), it should restart the same process some one else started earlier.
Any idea/way to go?
Here's a possible way to handle this issue.
First, package your nodejs program as a Windows Service. Here are some suggestions about how to do that. It's not hard. How to install node.js as windows service?
Then you, or anybody else, can use these command from an elevated-priv cmd.exe or powershell, to stop and start the service.
sc.exe stop yourServiceName
sc.exe start yourServiceName
If they're on another machine and they have appropriate permissions they can do
sc.exe \\YourMachineName stop yourServiceName
sc.exe \\YourMachineName start yourServiceName
Services are also handy because you can configure them to restart if they crash. And you can configure them to start automatically when the server starts up.

Asynchronous Process doesn't seem to work on my prod environment

I'm currently working on a rather complex PHP5/Symfony 2.8 project. In this project, I have a command that can be called by a Crontab, manually in console, or using a button on the website, that is used to call a webservice on an external site, which gives me an xml file, that I manage to import into my database using SimpleXML.
The command works like a charm on my local dev environment, no matter how it is called.
But for unknown reasons (which is why I'm posting here), on my int or prod environments, which are located on external servers, calling the command from the button on the site isn't working.
My button is triggering this action :
$process = new Process('php '.$kernelRootDir.'/console my:super:command');
$process->start();
As the command is kinda heavy, I can not afford to wait for the command to be completed, which is why I'm using process->start rather than run. I'm not in need of logs for it, so that's fine that it just starts the command and let it run while the user can go on another page.
And again, this works great on my local environment (debian 7 VM), but not on the distant server (not sure what it is using). However, if I manually launch the command via console or let the crontab call it, it runs perfectly until the end. That's just triggering it from my controller via Process that doesn't work.
This is pulling my hair off my head since yesterday, but I can't figure out why the command isn't even starting on the prod environment.. Any tips ?
Update : Tried to make my command only dumping a small "it worked" message, and using wait() and getOutput() methods to get the result in my controller. On my local environment, I instantly got my message as a result from the controller using dump/die combo. On the distant server, my command trigger a ProcessTimedOutException : the process exceeded the 60 seconds timeout.
So there is really a problem with Process being unable to launch a custom command, though that command works when called manually on console.
Okay, after struggling since two days, I found that the distant server might be responsible of this, it seems that if I don't wait for the process answer, that process is killed instantly. I don't know why, I don't know how, but it seems like it is.
So I started searching for an alternative solution that was not using Process. And I found something. I can use the php exec() method to launch an asynchronous call by doing so :
exec('php '.$kernelRootDir.'/console my:super:command > /dev/null &');
//Apparently, using "&" launch the command asynchronously.
All my tests have been working on my production server so far, so I'll keep that.

Run command before exit apache/xampp

Is there a way to run a command/method when Apache is about to exit?
I have an application running in windows with Xampp (local use only), and want to make some kind of cleanup method when this application is ended by the user, which happens when Apache's stop button is pushed.
So any kind of event fired by Xampp or apache, or even php that I can use?
And the command can be from cmd, php, whatever.
OBS: must be something before apache's closed, so check windows
process list isn't an option.
IMO, I would suggest you make a batch file that do stop Apache and call your cleaning command before or after stopping command.
This way the batch file is independent from XAMPP in case of re-installation or changing environment.
The step to reach the goal:
Run cmd as administrator
Go to your XAMPP Apache bin folder
Install Apache as service, httpd -k install
Now you should be able to manually start and stop Apache by command line
httpd -k stop
httpd -k start
You can learn more commands, check the link
Now make a batch file call it any thing you like, that do cleaning job and put it before or after you stop or start Apache
Example for testing cleanandstopapache.bat:
clean.bat // or what ever calling cleaning command.
pause // just to test pause
httpd -k stop // stops Apache
Notes:
Normally you start and stop your XAMPP via GUI. Using service has the same effect the only different is, that you gone use command line to start and stop your Apache, that said you can put any script before stop Apache to do the job.
You can either use XAMPP GUI or XAMPP services, not both.
I have test it on my machine and it works.
It is possible to give the service a unique customized name so you can see it in Windows Services.
You can inspire by an answer that it works fine for this stackoverflow question "Run PHP script in background on Apache start/restart(Windows Server)"
Here the link of my solution
In your case, you must replace
%APACHE_HOME%\bin\httpdVendor.exe -k runservice
by
%APACHE_HOME%\bin\httpdVendor.exe -k stopservice
I didn't test this case, and i hope that it will help you
Do not hesitate to ask me questions on your needs :)
Good luck :)
There is a HUGE difference between application-end and Apache-end. Which one do you mean?
If you need a clean shutdown during but at the end of your Application, use a __deconstruct() method in the appripriate class.
If you need a step further in time, use a combination of ignore_user_abort() and register_shutdown_function().
If you mean Apache stopping, you should search for a script or tool that watches the process list and acts when the Apache process is not in this list.

RPCS on Server disappear after idle time of 15-20min

I am really sorry for my Poor English.
I have created simple websocket game with voryx/ThruwayBundle for Symfony. Game uses RPCS registered on Server. Everything works fine but when I leave for about 20 mins RPCS are no longer available. And I have to restart websocket server to make them avaiable again.
I tried to register my rpcs as workers and I can see them running but they are still unavailable
websocket server process status
The annotation I use to register RPC is
/**
* #Register("games.snake.newplayer",serializerEnableMaxDepthChecks=true, worker="add-snake")
*/
I run server with command
nohup php app/console thruway:process start &
You can see it on http://amusement.cloudapp.net/
I am using Ubuntu 15.10 server created in Microsoft azure if it's any help
I don't know what I can do to make those RPC available anytime without restarting websocket server. Should I make some cron action to reset websocket server if they're stopped responding and how can I do it.
Edit#1
RPCS work great on my local machine Ubuntu 14.04
To prevent disapeearing of rpcs I created symfony console command to ping them with some test data. Next I registered this command as cron job to be executed every minute.
I could't find the source of problem however it's easy way to avoid it.

php artisan serve equivalent for production

So what exactly is php artisan serve doing? I currently have a site up and running on apache and I am trying to get a websocket framework up for real time chat. The websocket is a php daemon that runs in the background and listens for events, see the package here.
So I am using the command
php artisan serve brainsocket:start --port=8080
to start the server and everything works great, however this only works while I have the terminal open and I have read in 3-4 SO posts that artisan serve is NOT to be used in production. So how can I run the laravel package start function on port 8080 without php artisan serve, and so that it will be persistent after I close the terminal?
I'm surprised this hasn't been answered yet.
In production you want to run a real web server like Apache or Nginx.
With Nginx you would use php-fpm as your runtime and you would proxy requests to it.
Here's an example from Nginx's website.
https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

Categories