Website to computer communications - php

I am working on my senior project at university and I have a question. My advisor and other workers don't know much more on the matter so I thought I would toss it out to SO and see if you could help.
We want to make a website that will be hosted on a server that we are configuring. That website will have buttons on it, and when visitors of that website click a certain button we want to register an event on the server. We plan on doing this with PHP.
Once that event is registered (this is where we get lost), we want to communicate with a serial device on a remote computer. We are confident we can set up the PHP event/listener for the button press, but once we have that registered, how do we signal to the remote computer(connected via T1 line/routers) to communicate with the serial device? What is this sequence of events referred to as? The hardest thing for us (when researching it) is that we are not certain what to search for!
We have a feeling that a python script could be running on the server, get signals from the PHP listener, and then communicate with the remote PC. The remote PC could also be running a python script that then will communicate with our serial device. Again, most of this makes sense, but we are not clear on how we communicate between Python and PHP on the web server (or if this is possible).
If any one could give me some advice on what to search for, or similar projects I would really appreciate it. Thanks,

Both php and python can communicate via sockets, so I guess that is a good bet.
In PHP, when you receive the signal from the click button, open a socket to your python app with socket_create.
In python, you would need to implement a server socket (SocketServer) that listens for a connection.
Try reading up on sockets communication in general and socket programming in php and python specifically.

You can set up a web server also on the remote computer, perhaps using the same software as on the public server, so you do not need to learn another technology. The public server can make HTTP requests and the remote server responds by communicating with the serial device.

Related

Make socket resource accessible through several pages in php

In PHP, is there any way to create, connect and maintain an open (socket)connection so that the connection object can be accessed on several pages?
Imagine a small windows based client program that connects to its server software when you start it. You can send a couple of commands to the server using buttons(lets say start and stop calculation), and receive confirmations on my input.
In this example, when "started", the server will do some counting/calculations and send some values every second to the client which shows this every second until the server is done with its job or you send the "stop" command. The client will also stay connected until you close the program or click some disconnect-button.
How could this client work as a web client running in PHP on the same box as the server software?
I managed to send commands and receive feedback using socket or pfsockopen, but I'm having trouble maintaining the connection since I don't want to reload the page.
I don't want to reload the page every second, so I figured I can use Ajax to execute PHP scripts to read/write to the server without reloading the page, but the script files I execute on the web server can't find my connection resource. I tried saving the resource in session with no luck.
Alternatively, is there any better way of achieving this?
Also: the server software is an old piece of VB6 software, and the web server is on the same box as the VB6 software. The PHP site will work as an interface.

Website to connect to a client desktop application

I have an application written in VB.net that runs on a clients pc.
I also have a website written in mostly javascript, http and php.
The thing I want to do is to connect the website to the application, so that when i.e. a certain button is pressed, it connects to the client application and raises an event.
I have tried approaches like TCP socket communication by having a TCP Socket Server running in the background of the client application. I can connect to the server by having a client connection from another vb.net application, but whenever I try to connect through PHP it fails. (I have only tried PHP since server-side scripting seems to make more sense in this case)
Another approach I have tried is to have an HTTP server running in the background of my desktop application and then have a PHP script connect to it, that fails as well.
One thing that I've been thinking about as a last resort is to simply have a textfile on the webserver and a PHP script writing to it after given parameters and then have the client application to read the file every few seconds. But this wouldn't be very efficient with larger amounts of data, would it?
What is the proper way of doing this?
If you have any questions about the code I've been using, feel free to ask.
If you don't get my blurry explanation, try this image: http://i.imgur.com/8njxVFj.png
Thanks in advance.
To have your data more organized i would suggest you to store your data on a database server for example mysql (which is free).

chat with socket ajax php and nodejs?

I am writing a chat application for mobile & web using PHP and nodejs-socket.io.
I am using Android to post messenger to PHP - PHP to create a new socket (net library on nodejs) and that response messenger to friend via nodejs.
A (via HTTP Request)-> PHP (via socket)-> NODEJS (via socket.io)-> B
(web - websocket / android)
I was trying A->NODEJS->B use all by socket.io, but the message is slow when the number of users increases.
I found the time for sending messenger from nodejs to B device (chatter) very fast, but socket PHP sending messenger to NODEJS is slow.
I see the socket in PHP/nodejs is opening and closing many times in a short period of time.
Please help me make my application run faster, or suggest a solution?
I expected to try using java, but can anyone tell me anything about websocket performance, i.e. socket.io vs. java socket speeds?
Thank you.
Websocket performance really good, really fast. I tested on Chrome (PC) but not on mobile phone yet.
And Java socket is simple and easy to use. Why don't you use java socket to connect directly from Android -> NODEJS without making any HTTP request and PHP bridge?
The reason why PHP socket repeatedly open and close: There are many reason make your code open and close repeatedly, may be there are no loop in your PHP code to keep the connection. Can you show your detailed code of the problem please?

PHP doing SNMP walk on remote devices/clients?

I am trying to create a new application for our company to do an SNMP walk.
Here's what I am trying to achieve. The customer logs into our website. Clicks a button saying "Do SNMP Walk" and a PHP script will do a walk, and parse the data into the MySQL DB, and that's it.
Is this possible to do with PHP?
I was reading on http://php.net/manual/en/function.snmpwalk.php and I seen that it looks like it is, but I wasn't sure because the clients wouldn't be on the same network as the server the script is running from (we'd be using godaddy.)
Thanks!
If you're trying to SNMP walk devices in the client's network from your GoDaddy server, then the answer is no: you won't be able to do it.
SNMP is typically not passed through firewalls, so you would need to deploy your PHP code on the same network as the client.
This is wrong... snmp, is passed like any other data packets, unless the router is specifically configured to block it. I frequently use it to access routers across the internet to different providers and such.
Its possible that GoDaddy has blocks on that, but I have never seen this. You may want to install a copy of snmp on your computer and do an snmpwalk from the commandline.

Questions about sockets in php?

1- Let's say my computer ip address is 111.11.111.11, and the server that my php script is on is 222.22.222.22, so if i access and run the php script that is on the server and start a socket server, which ip do my clients need to connect to?
2- Is it possible to have a socket running on php which keeps reading, and responding to the clients until I close the browser, So basically what i'm trying to do is to start a socket which keeps reading, and accepting clients, and keeps communicating with them multiple times with each.
thanks for the answer, but i think i didn't explain well enough on my question 2, so let me make it easier:
Is it possible to create a chat server using php? because the point i was getting into was if it's possible to accept multiple clients and keep them alove.
222.22.222.22. But it sounds like you are starting up a socket server in response to a HTTP request. Probably, that won't work as intended, since the PHP interpreter terminates after the response is sent. If you had permissions, you could fork a separate socket server process, but I don't know what that would accomplish.
No. Even if you kept the interpreter running, there is no way to tell when the browser closes. The closest you can get is determining the browser (as determined by cookies or IP) stops communicating with you.
1- 222.22.222.22, your server's IP.
2- When a visitor arrives you can spawn a 'socket process' and implement a client side 'heartbeat' application using JavaScript/AJAX, but that implies you running the socket backend script (possibly) for a long time, which may cause problems (Like having a lot of PHP processes open, depending on the way your web server is set up this may cause problems)

Categories