i want to use AMP PHP and create a Project. So i started with one of the examples on github and i can see hello world.
Now if i make changes to my code, i have to restart everytime the server. but this is not how it should work right?
Do i have to run some kind of filewatcher which restarts the server everytime i change the code? or should the AMP PHP Server work as Proxy which then call php-fpm instances like an NGINX server would do? If so, can i use the async libraries without the Loop? (since the loop is on server)
How to work the framework? it seems that i understand here something wrong.
Best regards
Yes, you'll need to restart the server on changes. You can use a file watcher to do this automatically. PHP doesn't provide a hotreload feature currently.
You can't use cooperative multitasking without a scheduler / event loop, no.
Related
I am working on a site that is hosted on
goDaddy, through cPanel
The client wants to transition from their old PHP server to a node.js system.
They would like to implement new code in phases while leaving the old site up and running. The old and new code would be running on the same server.
I have a good break point for phase 1, but am not sure how to allow the PHP and node code to run simultaneously and listening for requests on the same server. I am familiar with node, but not as much with PHP.
In short- Can I have PHP and Node.js running simultaneously on the same server? If so, what considerations need to be made?
Thank you in advance!
You will most likely want to make it to where you migrate to the node.js service one endpoint at a time. That way you can test, debug, and fix things quickly without too much work. I recommend you use express for your router and whatever database connector you want. You will want to canary test between the two as well.
I'm a LAMP guy, and now start learning WebSockets via Ratchet. So far so good following the start up docs here, and hence i'm able to run the Ratchet Server, like this:
$ php server.php
And then my Javascript Clients can connect to it, etc.
But..
As a LAMP guy, i'm very used to have Apache (or) NGINX as the "Server" for any PHP files to serve to public. Now... should i just run that above command in my terminal, and that's gonna be the Ratchet Server?
Is there a way NOT to run the server like that? (or) Is there a way to let Apache (as an example) manage the Ratchet Server? Which means, let Apache start/stop the Ratchet whenever i type:
$ service httpd start
$ service httpd stop
I'm more confident this way. Plus, the SSL handling, etc also would be then done by Apache more easily. Am i right please?
Please kindly suggest, as i'm very new to this area. Thanks all :)
You indeed are right that running it in the command line is not a production ready solution.
In the last page of the tutorial (deployment) there are some ways to do it. For example, hypervisor is entirely explained how to set it up there.
If you don't like hypervisor usage, then you could try to just write a shell script which is executed on startup, that starts the server.php (less good solution, yet easier)
The ssl part you want to use is possible using a proxy with apache.
If you are using Apache web server (2.4 or above), enable these modules in httpd.conf file :
mod_proxy.so
mod_proxy_wstunnel.so
Add this setting to your httpd.conf file
ProxyPass /wss2/ ws://ratchet.mydomain.org:8888/
If you have any more questions please let me know.
I have created a simple website that will help me in my many projects by creating a sub domain for each new website project that I take on.
I keep going back to the older websites I've created so I have decided to keep all of them as a sub domain on localhost.
My PHP code works fine to add the information to the relevant files.
But I need to restart Apache for the changes to take affect.
I know PHP runs from the Apache service. Is it possible therefor to stop and start or even restart the Apache service from PHP code?
Yes, with exec()
exec("apachectl restart");
You might want to allow programs to close themselves before just shutting down the server, so I'd recommend:
exec("apachectl graceful");
Make sure PHP doesn't run in safemode (<= PHP 5.3), as these functions won't be available then.
Please note, this is how I restart apache on my server, you might have to adjust the command.
Also think about the permissions. Not all users (and probably not the one running php scripts) have permission to stop the server.
I run an executable called Test.exe via exec which in turns runs Outlook.
I am able to run the Test.exe fine but I get the error:
Rejected Safe Mode action : Microsoft Office Outlook. in the windows event viewer.
If I run Test.exe myself via DOS it works fine and no errors. So its something to do with how PHP is running this exectuable. I've enabled apache to run as an admin account but the same thing happens.
What else should I be doing so that Apache can run the executable without any problems?
It works from the command line but not from the Apache process. Not surprisingly because Apache probably runs as a service, with a system account (Non-Desktop interactive).
If you reconfigure the service to run as a user with the right to logon locally and mark the service to be allowed 'Interaction with Desktop', I expect you could do this.
However, I'm at a total loss why anyone, at all, would want to start Outlook from a webserver application....
Sehe is right (but for some reason I cannot comment to his post, whatever...). Usually, you should access MS Office facilities via external code using specific OLE interfaces. You never use CreateProcess to start Outlook or Word from your program, it would be pointless because how can you control it after launching it?
I suggest you to check if you really need this, and if there's a more clean way to do it. You can try to create an external C#/VB.NET executable that performs all the automation you may need to do with Microsoft Outlook, indeed.
What is the actual scenario?
And, I don't like to correct people but if I don't, someone else will in the future and it'll be annoying. Don't say "via DOS" when you use a prompt under Windows. :D
i too am perplexed by would anyone would want to do this.
If you REALLY wanted to do this i guess you could run it as "start test.exe" or write a batch file that would run it. basically anything that would cause a different process to be the one actually launching the app.
I was wondering, whether knockd http://www.zeroflux.org/cgi-bin/cvstrac.cgi/knock/wiki would be a good was to be able to restart apache without logging into ssh. But my programming question was whether there is a way to send tcp/udp packages via PHP so I can knock via a webclient.
I am aware that this is not the safest way of doing it, but I will only want to do things like update the svn, restart apache without having any passwords in it like with using ssh to do that.
You may use fsockopen() functions... but what you are doing(and the way you are doing it) is very risky from a security standpoit.. as it had been said, ssh is the way:)
If you really want to restart the apache server by using remote access (non-ssh) you can create a small php-daemon, that just watches for a specific file,(ex: /tmp/restart.apache) and when that file appears run exec("/etc/init.d/apache restart") (or whatever the command is for your distribution). This daemon should run as root... and the thing is that the whole security thing is up to you this way, you have to make sure this cannot get arbitrarly executed...
Your portknock ideea... a simple port scanner may restart your apache by mistake:) portknock is recommented to be used in conjunction with a ssh auth , not directly with apache:)
Seriously, you do not want to do what your trying to do.
You should look into calling your remote server through some sort of secure protocol, like SSH. And on the client side, have a small PHP utility application/script that executes remote SSH commands (preferably with a keyfile only based authentication mechanism).
Why not have a PHP script that calls "svn update"? As long as the files are writeable by the user Apache runs as, it works great. Just hit that URL to update the website
For SVN you have whole PHP api, try search SVN on php.net