Converting simple php web app to LAN only - javascript

Apologies if this is not the best tag to use. I'm after some basic thoughts on the best way to do the following without using the net.
I've been asked to build a simple ordering service for a busy takeaway. They're looking for something like you get in McDonalds ie a large screen showing the status of order numbers.
I've created a basic system in php/mysql which consists of 2 pages which look very similar however the staff one has the ability to change the progress when an order item is clicked. The 2nd page is the one that will be displayed on the customer screen and simply queries the database and outputs the results, the page refreshes every 10seconds or so.
The idea is that the customer page will run on a large screen in the restaurant while the staff page will be on a couple of touch screen tablets. As there is no need for internet usage I would like to move this to an internal server but am not sure where to start?
Can I simply setup a server using an old PC, install php and mySqL on it and set it running? Do I then just reference the IP Address of the "server" on the tablets ie something like 192.1.1.1/staffpage.php?
Or is it a bit more complicated than that?

You have the right idea.
I would suggest building a LAMP stack (Linux, Apache, MySQL, PHP) on a cheap linux box. As ivanivan suggested, a Raspberry Pi would be ideal.
There are many tutorials on setting this up with the Pi and Linux.
However, if this is too technical then using an old computer with WAMP/MAMP would also work.
When the server is setup and running on your local network using 127.0.0.1 or localhost, then the ip address of that machine should be reachable by other devices (assuming your firewall allows it).
You could simply load the webpage in a fullscreen browser and use client side javascript to refresh the page every 10 seconds.
Or if you wanted to get clever, you could use ajax or websockets.
On a side note: Another completely different option could be to use a node.js server on a Raspberry Pi and do away with Apache, PHP and Mysql all together.
I hope this helps.

yes you can use the localhost and you need a corn job to refresh the page every 10s

Related

Live Update Software for Web Pages on Multiple Screens

I have six devices on/above my desk:
A 4k TV
An Ultrawide monitor
Two laptop computers
An iPad
An android phone
All are connected to the internet and browsing mydomain.org/page, an html page that I am editing using one of the laptops, which has a full page of code. When I press a button on my Wacom tablet that I rerouted through Wacom smart actions to run a script, my code is uploaded over FTP to my server. Right now, I have to reload every page on every device to see the updated results. I want to make a javascript to run on my site that has a LiveLoad() global function. When I execute this function from the DevTools command line, the script stores a cookie that the device is a debug device.
All pages with the script will now enable a small icon over the page that when set to 'live,' the script will open a connection through secure web sockets with an update server that stores up to 10 connections (perhaps only from approved IPs, so that only I can use this on my live site), each registered to the page they are browsing. When I update mydomain.org/page or other pages, my script securely opens a connection and POSTs a secret code to the update server, telling it to send a message over web sockets to all connected debug devices with that page open. On fast internet, this truly will be the ultimate website building setup if I can just overcome this design hurdle.
What I don't want:
Anything more than a single php script for the server-side implementation. Shared hosting. No root access. No Node. No fancy crap. Single PHP files are the only option.
Bloated javascript addons. Bare minimum code for receiving a single type of message (an update is needed) is all I need. Perhaps later I can make it more robust with a second type of update (a hard update) where a php script processes all the fonts, scripts, images etc on a page and adds a random query string after them to force a hard-reload of all page resources.
How can I achieve this? Where to start with php web sockets? The internet has proven to be a cynical wasteland of bloated php libraries that require installation in a node enviornment to freelancers struggling to make scripts off of the 2013 websockets API documentation, with no good, simple solutions around.

Is it possible to load different webpage based on clients internet speed? If so how?

If you have a website running on any server. And the website comes in three different version: Heavy, Medium and Lite. Now you have to load lite version if clients speed is below certain limit (Lets say 500kbps), Medium version (Lets say >500kbps and <25mbps), Heavy version (Lets say more than 25mbps). Can you do it?
I was thinking making a server side script that first check the connection speed with client (don't know how), then based on the speed result redirecting them to respected website.
If there is another way, please do tell...
There is no definitive, reliable way to do this and I recommend that you focus on building an optimized site for your intended target audience and their devices.
Internet connections are pretty good around the world. The effort and ongoing maintenance in updating and managing three frontends is not feasible. Instead, focus on serving optimized content and use modern techniques to serve media targetting screen size and device. Limit unnecessary media, compile and bundle scripts, ensure servers are serving gzipped content and place your servers/cdn's near your audience.
If you did, however, want to pursue this exercise you can play with the following idea: You would need to make an initial request to the server to get a timestamp - we want to work with the server's time, not the client which could be off. The client receives the timestamp and responds immediately, passing the timestamp back to the server. The server considers the difference between the two and redirects accordingly.
The problem is that connections are not consistent, and you cannot rely on that first connection to represent the client's connection quality. There may be a dip in connection quality as they are connecting etc.
To maintain two or more server side codes is not easy or ideal. Focus on optimization especially on the website assets such as images. Images form about 75% of site load times.
Ideally you can have multiple image source to start with img srcset.
What you are talking about is obtainable with respect to images and videos . You can have more than three images and the browser will select the best based on the available connection speed.

Printing using Nodejs

I am having a really hard time figuring out how I am going to handle printing in my Nodejs application. I have a website where there is a bunch of purchase numbers. I want the users to print this numbers in a click of a button. These numbers are dynamically generated after querying the database.
I started using this npm library to print the purchase number. When I am developing in my local computer this library is working fine. I made it so that each time the user presses a button in the front end, I make a post request to my Nodejs Server which prints to the printer that I configured locally.
The problem is that I want to eventually deploy my website to Heroku. Website will be used by a group of people sharing the same network and printer. I do not know of a way to set heroku to communicate with the printer using this package.
I also thought that printing directly from the front end might be a better idea, but I have to open google on kiosk mode and then do the same for all the users that are going to use this website. Also, most of the users will be using a tablet device so configuring printer in those devices will be difficult as well.
I did not find anything online that I can use as a reference. Any advice or suggestion will be greatly appreciated.
As for nodeJs printing I have no experience. It seems that you can use certain packages to print a pdf as given in the example answer here: Node.js : How to add print job to printer.
As for generating from html to PDF, that should be easy to find, less easy to style correctly though.
I would recommend doing it from HTML (you could still do the PDF conversion for more stable printing results)
From HTML
As stated, the API is rather limited, you can use window.print to request a print action.
Note though that you have some options to make your life better when calling window.print().
You can create the page in a separate window to get rid of bloat, like navigation etc, or you could actually hide that with css.
You might already be aware of css being included for certain targets e.g. for your website you probably want to use the screen target, but you can create a separate stylesheet for printing.
More info at mozilla
https://developer.mozilla.org/en-US/docs/Web/Guide/Printing

Browser timeout waiting for JSP to finish Java method

I really can't solve a problem: I've finished to write a web application during my internship which allows me, after a series of queries to Oracle DBs, to create my own tables on MySQL, then export the results in a custom fancy to XLS or PDF. The server side is in Java, the client side is in Javascript, some JQuery, and obviously HTML5. The server is set up with Apache Tomcat.
The method I use to run the queries and then export the results to a direct-download file (nothing stays in local, I use OutputStreams) is written in a jsp which I call by a button press from index.jsp.
As I was in local on my laptop with my own Tomcat, the browser waited patiently for the Java to end, then returned the generated files. Right now, after the remote deploy in a local server, the browser times out "casually" giving an err_no_response code. This happens both in Chrome and Firefox. The queries do take from 2 to 12 minutes to be done, and that's the problem.
I tried both polling with Ajax and websockets, but none of them worked: the firewall is in the way and I can't tunnel in a proxy it seems.
Any idea on how to keep the page alive while the server is running? Thanks.
PS: I can't edit indexes on the Oracle tables, nor alter them in any way. The queries are already quite optimized.
Also, I know I'm doing a lot of mistakes (plain Java code in JSPs...), yet this is the best I can do for now. Changing the whole logical structure of the code is hard at this point and I just need a painless solution to make everything work.

connecting javascript to php socket to communicate with Flash

I'm trying to build a projection installation for a university project, I want the audience to be able to communicate with the installation with their mobile phones.
This is what I'm trying to do:
- My Flash application will be running on a computer connected to the internet and will be connected to an XMLSocket hosted on my server.
- I need a javascript page which the audience can visit, mouse clicks (touches) will then send data from the javascript page to the socket server.
- Flash application will receive the data and so on..
Is it possible? I've been looking around for various resources, but they all require a flash app to be on the same page, which is not what I want.
I just need a standalone javascript page to be able to talk to a flash app.
Any suggestions or ideas for possible work arounds will be greatly appreciated.
Many thanks,
Will
Yes definitely possible. The server sits between the two (Flash and JS), they don't need to know each other exist. JS sends data to the server and Flash pulls it down.
I am not sure to fully understand your question.
There is no such thing as a "javascript page", javascript is a... script running in a browser environment.
In the case you want to use an Android/iPhone app environment I don't think you need javascript to do this.
But if what you want is to have a web/wap page accessible to the mobiles, with a user interface, buttons, text field, whatever, which communicates in both directions with your XML socket, you need to build your user interface in HTML, and then to use some javascript to call your XML script and translate the response in the interface. If you have a server, can't you host also your UI there? The cross-domain issue would be avoided, otherwise it's easy enough through any server-side script (PHP?).
So yes it seems very possible, but I don't see what you mean by "they all require a flash app to be on the same page". Here's what I understood: Your Flash app is not what you want to load in the mobiles, it's connected to the server's XML in/out and working fine. You just want an interface communicating with this socket. Right?

Categories

Resources