Make socket resource accessible through several pages in php - 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.

Related

Looking for a way to trigger a script when our Biometric inserts a new row

In our office we have a biometric scanner that inserts into a MS Access Database running on one of our local servers. That's just how the thing is built and we can't get into it to modify how it works.
We created a web-based attendance system that needs the Biometric information since the online system allows users to time in via the online form or the biometric scanner.
Our current setup right now is that every 1 minute, the local server runs a scheduled task in the scheduler to push the data to our remote server (this task is a PHP script) where the online app is hosted.
That slight delay isn't very nice and we'd like the data from the local server to sync right away with our online app, since sometimes the local server just dies and we don't know why.
TL;DR:
Is there a way to monitor any changes to the local server (MS Access) that will send the changes to our remote server using NodeJS or PHP? If there are other solutions available, those will be welcome as well.
The local server is running, a driver called ZK Attendance Manager with an MS Access Database. The remote server uses MySQL.
Thank you!
Even in SQL Server I try and avoid triggers if at all possible. Access does not have them per se... but here is an article I previously found in looking it up... because sometimes you just need the functionality. Granted I've never used a Data Macro but from what it says it may be able to help you in your situation.
Read:
MS Access trigger?

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).

Website to computer communications

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.

How to receive UDP broadcasts with PHP

I am trying to receive a repeated UDP broadcast with PHP and display it on a webpage on local host.
How would I accomplish this?
I would most likely have a daemon or server process running that would be responsible for receiving the UDP broadcast and appending it to either a file or database (this could be implemented in any language). I would then have a PHP page that either reads the file or queries the database for results and echoing the results on the page.
If you're looking for live updates, then I'd be adding some jQuery/AJAX scripting magic.

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