I have to connect to external server (lets name it server B) inside my php script. The easiest way to do that would be by using SSH2. But ssh2 is blocked due to security reasons and Net_SSH2 doesn't work (probably for the same reasons). And for now I have no possibility to turn SSH on, or change this webhosting. Thankfully cURL is working and I'm thinking about some alternatives.
The only thing that comes to my mind is to just write some perl script on this server B, put it into cgi-bin, then to connect to this script through cURL using some authentication and run some things on server B.
Unfortunately this mean to write some authentication and stuff, there are a lot of potential problems with security and stuff.
Anyone have a better idea how to overcome this problem?
Thanks
Related
Basically I want to use some kind of sockets (web sockets or node.js?) but I don't really know much about them and I want to send low latency data between html pages with javascript enabled on them.
I have php installed on the shared server and socket_connect() is a function included so i'm guessing php_sockets.dll is installed. I could potentially use this, but the php script is on a remote server so I don't know if i would be able to run it?
Should I use some other language that would be installed on a normal shared server?
EDIT: I don't have shell access..
http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/ this should give you a pretty good start in talking to php using html5's websocket api. You don't need Node.js to implement this.
I'm currently developing a PHP application that is going to use websockets for client-server communication. I've heard numerous times that PHP shouldn't be used for server applications because of the lack of threading mechanisms, its memory-management (cyclic references) or the unhandy socket library.
So far, everything is working quite well. I'm using phpws as the websocket library and the Doctrine DBAL to access different database systems; PHP is version 5.3.8 . The server should serve a maximum of 30 clients. Yet especially in the last days I've read several articles stating the ineffectiveness of PHP for long running applications.
Now I'm not aware whether I should continue using websockets with PHP or rebuild the entire serverside application. I've tried Python with Socket.IO, though I did not get the results I expected.
I guess I have the following options:
Keep everything as it is.
Make the application use Ajax in combination with Socket.IO - e.g. run a serverside script that invokes the client's ajax calls when data is submitted to the server.
The last point sounds quite interesting, though it would require some work .. Would it be a problem for servers to execute all the clients requests at one time?
What would you recommend? Is the problem with PHP's memory management (I'm using gc_collect each time a client sends data to the server) still valid? Are there other reasons beside the obvious reasons (no threading, ...) for not using PHP as a server?
You can try running your socket.io on a node server on another port on your server (that is if you are not using a hosting plan like goDaddy).
I am using it and the performances are really satisfying.
I have an apache server on the port 80 serving my php files, and my server-client communications are done using a Node.js server running socket.io on the port 8080 (dev) or 843 (prod).
Node.js is really light and has great performance, but you need to run it as a server. Nodejitsu.com is a hosting solution that has the websocket protocol available and is on beta, so it is still free for now. Just note that you need to listen on the port 80 with socket.io, this is a limitation from theyr network.
If you want your pages all to be accessed on the port 80 then you will need a reverse proxy like varnish .
I hope that helps! Have a nice day.
Are there other reasons beside the obvious reasons (no threading, ...)
for not using PHP as a server?
Yep, lots of socketfunctions are incompatible with each other and it's a hell to debug.
i tried something similar myself and quit frustrated sind every function i thought would make sense didnt do what i expected
I'm working on making a website/web application that displays images every 5 or so minutes, kinda like a webcam. The images are uploaded to an SFTP server. How can I access those from the web? Does anyone have any recommendations for what to use as well? Right now I'm looking at PHP but have checked out javascript and ruby as well. Only the application needs to ssh to a predetermined place, not the users.
I was suggested by a friend to use rsync and setup passwordless ssh. Anyone ever do this? or is this a bad idea?
If the application is the only thing that needs to SSH then you can rule out javascript immediately. It's predominately a client-side language in these environments.
You may like at Net::SSH ruby library, or I'm sure there's a php equivalent. I have used Net:SSH and it's fairly straight forward.
You need to write a server-side script that connects to the SFTP server and forwards the image to the client.
cURL has SFTP support.
PHP supports SFTP. You need to install ssh2 extension,
http://www.php.net/manual/en/book.ssh2.php
I'm trying to implement a socket server that will run in most shared PHP hosting.
The requirements are that the Socket server can be installed, started and stopped from PHP automatically without the user doing anything. It doesn't matter what language the socket server is written in, as long as it will run on the majority of shared hosting globally.
Currently, I've written a Socket Server with PHP that implements an Object Cache:
http://code.google.com/p/php-object-cache/
source: http://code.google.com/p/php-object-cache/source/browse/trunk/socket.class.php
However, PHP has to be compiled with sockets support, and not many servers run with PHP sockets support.
My real question is: What language should I implement the socket server in, and have maximum platform support and be invokable from within PHP.
In other words, what scripting language is the most common on PHP enabled Servers?
Or do I have to write the socket server in a compiled language to have it works across all servers?
Lets leave IIS out of the picture at the moment, just Linux servers. I don't think many PHP sites are running on IIS...
edit:
Sorry I think my question is not clear.
I'd like to know, what languages is best suited for creating a socket server given the following requirements:
The language must exist in shared hosting, alongside PHP running in Apache (not CLI).
The sockets support must be enabled natively, not via a required extension.
PHP must be able to write the deamon to file as well as start and stop the deamon.
I'm not asking for a solution for a single server. It has to run natively on the majority of shared hosting servers.
Any server can be stopped or started by PHP under Linux. Of course, if you are running a server which accepts sockets from the internet, then you can just connect directly to the server and tell it to shutdown. No need to go via PHP!
As for "starting a server from PHP", well, under Linux, anything can be started from pretty much anything. Just shell out to start the process and have it drop into daemon mode.
I'm a Perl fan myself. Not surprisingly, there's a
Perl Daemon library available.
If your hosting provider offers Perl script support, then you probably have permission to use "system" or backticks command. Then you can very likely start a daemon. However, you will need to use a non-privileged port (over 1024). Also, you should ASK THEM FIRST! They may not appreciate you tying up ports on their server. This is very definitely something you should discuss with your hosting provider.
It really depends on what the install requirements are. Often the easiest and most standard way to write a socket server is to write an inet.d service. This is a standard daemon on my unix machines, and it will fork a process and handle the socket level details. If you want your service to run on port below 1024 on Unix, this is one of the easier ways to get it done. However, the initial install requires root to configure inet.d.
If you shared hosting allows PHP to do an exec call, then you could start the daemon that way. Keep in mind though, it'll need to run above port 1024. You next need to decide if your program is going to be multi-threaded or multi-process. Typically Java programs are multi-threaded, while an Apache instance is normally multi-process.
Lastly, the host may have a firewall in place. This helps prevent shared hosting accounts from becoming part of a bot-net. If the firewall rules don't allow connections to other ports, you won't be able to connect to it remotely.
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