Check if a machine on local network is available with PHP - php

I have a PHP app runing on local network server (Mac Mini server with OS X Lion). There are several local clients (also Macs) accessing this app. Client machines are put to sleep from time to time. I need to be able to check from PHP server if the local clients are running (wake) or in sleep mode.
I have been successful of doing this with AJAX polling script, where I periodically ping the local machines and display status of a local machine in PHP app. The problem I have is that PING command initiates wake-on-lan on client machines if they are in sleep mode, and this is something I do not want. I would just like to see the status without waking the machine.
Can this be done?

check
pmset -g | grep hibernatemode
http://www.tuaw.com/2010/10/20/safesleep-lets-you-use-safe-sleep-on-demand-on-your-mac/

I would say you need to correctly configure the Wake-on-lan for those machines. Aparently they get awakened for every packet, which is probably not what you require. Usually WoL is configured to wake only on Magic Packet (on Windows it can be configured in Device Manager in the properties of network card driver). Then you will be able to use ping (or any other type of network traffic) to check if PC is online.

Related

Can't access localhost from a web server on my local network

This question will look like an essay because it is really weird (at least I can't see the logic on the problem.
I am running two computers right now, one Toshiba NB510 which I want to use as a web server, with XAMPP and controlled with VNC from my second (and main) computer, an MSI 2qe (with also XAMPP installed).
The problem is that when I run Apache and MySQL from the MSI, I can write to my local IP to access from any device on my LAN to access "localhost" (until this all ok) but when I run XAMPP on the web server I can only access to localhost from that computer (using the local IP).
Maybe it's a problem on my network?
Here is a map of the network (done in paint sorry)
You have two pcs. Both with your servers running, but you can't access one of them correct ?
The usual troubleshooting for this is :
first to check if you can ping it (to make sure it's on the network)
second to check if the ports you will use are open (tipically, 80 for
web)
finally to check if your server is set to accept incoming connection
(Apache config)
EDIT:
I've seen your picture now. If as you said, both PCs can "see" each other (as in, Toshiba can ping and access MSI, and MSI can ping toshiba but not access it) check if your commumator is the source of the problem
All solved, I installed windows 10 x64 instead of x32 and reinstalled xampp and all works

make keyboard accessible for client of remote server (Raspberry pi, php)

So here is what I wanted to do. I have an Apache2 server up and running on my raspberry pi 3, which is currently serving as a webradio using php commands and mpd/mpc. The raspberry is also connected via HDMI to a display.
I now like to have another page on the webserver which let's me start different roms in an emulator and display the output signal on the display connected to the remote server and and also lets me use a controller connected also to the remote server.
This is what I have done so far.
I have successfully installed Retroarch which is up and running.
I used exec("export DISPLAY=:0.0; retroarch -c /home/pi/path/to/config -L /home/pi/path/to/libretro/core /home/pi/path/to/rom") to start the emulator on the remote sever.
The problem is as follows. Even though I started the emulation successfully on the screen I cannot use the input devices connected to the remote server. How can I make the input devices of the server accessible with a php-command or something else? Can somebody point me to a solution to achieve this? Also the exec-command does not seem to accept my arguments besides the config file argument. I guess it has to do with user rights. But I am really stuck at this point.
Thanks for any replies.
Disclaimer: This is my first post. So I am sorry for bad terminology.

Remote X-Debugging PHP stuck while Server-2-Server communication

I am developing a web service using PHP, which will fetch data through a curl-call from a foreign website.
For developing, I use an Apache Webserver with PHP on a raspberry pi in my local network (call it Server A).
For testing purposes, I've also set up a dummy service to avoid to many useless or bad request to the foreign service. This dummy runs on another Raspberry, with the same Setup, call it Server B. On both Servers A and B, I've deployed XDebug. For developent, I use Netbeans.
When I remotely debug PHP-Scrips on Server A everything runs fine, unless I run/debug a scrip in which a curl-call to the Dummy-Service on Server B is made. If that is the case, the execution halts until I exit the debugging mode. If I do so, the scrips finish normal.
I am not sure what makes the scrip halt, so I've no idea how to avoid this.
What can I do to make debugging work in this case?
OK, found a solution. It obviously is a problem if both servers use the same port (9000) for communicating with the PC I am debugging on.
After setting one of the servers to 9001 instead, i can attach the debugger to one server at a time, depending on what port is set in Netbeans to listen on.

Apache localhost not responding to clients until reset

I have setup a local server on a regular desktop (not a server desktop) and have 3-4 client machines accessing the local web application I developed from the server via a WIFI router (server is connected to router via cable. All clients via WIFI).
When two of the clients are connected to the application all is well, but when a third (or more) machine joins in there are periods where each machine does not get any service from the server (the application webpage remains loading until I manually reset Apache on the server via services). At times the server responds when one of the clients refresh their page but most of the time I have to perform a reset of the Apache server.
This occurs roughly once an hour on average (6 hours of continuous usage) as the clients are using the application.
Server is running Windows 7 and Apache v2.4 with PHP v5.4
Server and all client machines are running AVG internet security
Firewall is handled by AVG Internet Security
Is this issue due to the code in my application, desktop not being able to manage requests like a server machine, antivirus or a mix of the three?
If so, how can I set-up the server to reset automatically?
Thanks
UPDATE
It is a application where users write reports on files after reviewing information
-Frequent sql requests for file data
-No images
-Some pages contain multiple sql queries that represent the page content
-Network has no internet connection
-Code does not make requests for external information from the internet
-All client machines run the application on Google Chrome web browser
But it rarely happens but sometimes the amount of connection is restricted by the third-party interface being used by the application. We are unable to figure out the reason unless having more details like what content of your app, and the error code apache or HTTP returning.
This kind of situations is difficult to track, especially on Windows where diagnostic tools aren't as readily available as on other platforms.
I suppose you can try and check the antivirus by either running server and clients with no antivirus at all for some hours, or disabling and re-enabling the antivirus when the hangup occurs.
Apart from that, you would need to pinpoint where the error occurs:
in the connection stage (Windows OS is the problem)
in the response stage (Apache is the problem - try fiddling with the child spawning parameters)
in the management stage (PHP is the problem - you can probably check this by changing the setup from PHP-as-a-module, and PHP-as-CGI-application)
in the response stage (that is, connection to the SQL server). You can check this by setting up some pages that use different combinations of session, database, and output buffering and see whether those pages remain reachable even when the application is hung up.
For an example of the last, if a page such as
<?php print date("H:i:s"); phpinfo(); ?>
remains reachable and correctly refreshes (that's why the date() command) even when the app does not respond, this demonstrates that Windows, Apache and PHP are "innocent", and either the SQL server has issues, or you do not interface with it correctly. It might be for example be the case (though unlikely in this instance) that the resident PHP module is accumulating connections to the SQL server and not releasing them, so that after a while you need to stop Apache (thereby freeing the module) and restart.
If this were the case, even if it's not a "real" fix, you can set up Apache so that all children die and are replaced after a small number of requests (once it was 150, but when leaks all but disappeared, I believe that the default became 0 -- Apache children no longer die. Check it out, I might well misremember).

LAMP Web Server: Executing Application on Server Side can't detect USB device

I have set up a LAMP Web Server and I am looking to run an application on the server side when the client clicks a button on the servers web interface. This application will look for a certain USB Device, by Serial Number, open it up and send a packet of bytes to the device.
I have an index.html, which only has a button with an action to call my test.php file which uses shell_exec() to call my application.
When the application is invoked through the web interface, the application writes out an error indicating that it couldn't open the USB Device (this a built in error for this application, so the application works, it just can not locate the usb device).
But when I invoke the application via the Terminal, the application finds the usb device and writes to it no problem.
I am looking for some advice! Simply is what I'm doing feasible? If so, how can I get the application to find the usb device when invoked via the web interface? I have a feeling it has something to do with permissions, you never know.
test.php:
<?php
echo shell_exec("/home/pi/FDTI_test/FDTI_test_application");
?>
NOTE:
The usb device is connected, works great with its driver, and is connected to the server via usb.
The application works when invoked via the terminal on server side, but not when invoked via web interface.
I think your on the right track with this being a permissions issue.
In a typical LAMP stack, the php process runs as a module in the apache process, unless you've configured it differently. In my server OS of choice, the php process runs as the user 'www-data' by default.
Probably the easiest solution would be to give sudo permission to your web user account, and set the sudoers file to NOPASSWD. This is very insecure, so only do this in rare cases.
<?php echo shell_exec("sudo /home/pi/FDTI_test/FDTI_test_application"); ?>
The next easiest option is to give the web user account permission to write to the USB device directly. Depending on your distribution, you may only need to add the user to the 'adm' group.
sudo usermod -a -G adm www-data
Again, this may not be the most secure method, but more secure than the first option.
Lastly, you could look into the hardest solution which would be to install a patched version of apache which allows suexec. This is about as equally as insecure as the second option, but much more difficult to implement. (I would have included a link to a tutorial, but I'm limited to 2 links as this is my first answer.)
Hope This Helps!

Categories