Is there anyway I can create a page on my website (PHP if possible) that would show the current status of my website and when it has/will have down time?
For example, could be similar to Google Apps Status Page at https://www.google.com/appsstatus
Thanks in advance
The best solution is to make a PHP script which loads one of your pages, looking for a specific content : if it finds it in a reasonable time, you can consider your site okay, if it doesn't find anything, or if your site takes too long to answer, you can tell you have a problem, and take action (for example, sending an email).
This script has to be launched regularly, so a cronjob has to execute it every x hours or so.
And, of course, it has to be on another hosting provider than your first website, because if there's an issue with the host, you can't tell it if your check script fails to load.
Edit : if this is complicated for you, some services can do it for free, like this one I found just now : https://uptimerobot.com/
Related
I'm trying to force to reload a (second) page if a criteria is met in php
But if the criteria is met, i want the page to force reload everywhere, even if 10 people have it open at once for example.
for simplicty lets say the code is like this:
in /filelocation/script.php:
if {$data == "ok"}{
reload/refresh "reload.php" if it's open somewhere;
}
I came across a software that basicly does this, and i want to understand how this is done.
(it works cross device somehow, so i asume its done through php somehow)
Well, in your PHP code, you cannot simply reload/refresh something for all the users connected. This is simply because the PHP code is only executed when your browser requests a page on the server so it's only executed to build the HTML response and then it stops executing. Once the browser has the HTML response it will render the page and then it waits for an action from the user to do something else (such as clicking on a link or posting a form).
I imagine that you would like that when a specific user does something, like posting a comment or buying a product, you would like all the other visitors to be notified that a new comment has been posted or that the number of products available has been reduced.
To do that, you need to implement some JavaScript which is executed in the browser of each visitor. The idea is to keep a connection with the server with the help of web sockets. This way, you can inform the browser that something has changed.
You could google to find some examples of PHP apps using web sockets. The first example I found:
https://www.twilio.com/blog/create-php-websocket-server-build-real-time-even-driven-application
Another solution could be to have some JavaScript doing some pooling, meaning that every N seconds, it executes an Ajax request to the server to ask if something has changed. This can be done with the help of setTimeout(yourFunction, 10000) to call a JavaScript function every 10 seconds. This function will do the Ajax request and then update the part of your page that needs to change. Just be carefull that if you get a lot of users on your site then you'll produce quite a lot of load on your server. So this wouldn't be a good solution, but it could be an alternative to the web sockets.
I have a webpage which scrapes the data from a page and updates a database. I want it to work automatically (I mean it scrapes data from a page and updates a database) even when my laptop is off and I am not browsing the that page. Rest of the page will pick the data from database from now. Question is how and which function I should write which will run the page let it scrape the data and store it into database. Please help me; it is in php for the website.
Host your website so that it is up 24/7 and write timers and event handlers in php Google for them you will find tons of concepts and code
Runwhen or Cronjobs could helo you.
For runwhen checkout the website: http://code.dogmap.org/runwhen/
You create a shell-script (or something else) which is called by runwhen every X minutes. For examples see the website.
Crontabs are supported on every system.
But the question is confusing ...
I want to write a little program that will give me an update whenever a webpage changes. Like I want to see if there is a new ebay listing under a certain category and then send an email to myself. Is there any clean way to do this? I could set up a program and run it on a server somewhere and have it just poll ebay.com every couple of minutes or seconds indefinitely but I feel like there should be a better way. This method could get dicey too if I wanted to monitor a variety of pages for updates.
There is no 'clean' way to do this.
You must relay on CURL or file_get_context() with context options in order to simply get data from URL, and, in order to notify you when content of URL is changed, you must store in database snapshots of page you are listening. Lately you are comparing new version of crawled content with earlier created snapshot and, if change in significant parts of DOM are detected, that should be trigger for your mail notifier function.
I have a situation where an event have to affect several web pages on an event is triggered.
Its like in GMail. I am developing a project based on online stocking trading system for my college. There are asking for a facility where the administrator or the dealer doesn't need to refresh his end of the application to view the new orders placed by the customers at the other end of the application.
As I said its like GMail, wait for the event to happen, listen to it and update the page.
I am good at JavaScript and jQuery that I can do this within a page: event listeners. But how to do this across several pages.
You can also consider another situation: A waiter, a cashier and a cook in a hotel, all have a PDA with them, any of them doesn't have to refresh their instance of web page to update the orders placed.
How can I achieve this? Is this possible?
I say I am good at javascript but I have my limits and doubts.
I use jQuery and PHP.
Thanks in advance.
PS: I know how to refresh the page or iFrame for every 5 seconds or so.
Edit 1:
As for additional details, I want to something similar to below that is done in java
synchronised(sync)
{
sync.wait()
}
The code may not be accurate, this was from my lab experiments. But the concept is similar. Server waits till the client made a move and this is repeated for a lot of time.
Edit 2:
Another best example is a situation we always face in the internet: Complete a survey or something to enable a content to be downloaded.
My trading system needs such a thing. The dealer page always listens for the client page to act with the server. Upon such thing, the dealer page is reacted to that action. In this case placing an order.
If there is several page instances on one browser, you can use javascript web worker.
ELSE
Use "Long pooling" OR "ajax quering"
Long pooling demo: How do I implement basic "Long Polling"?
What you do, you always query server for new information. If there is new information, you return it. Then javascript will see that there is new information and it will show it.
Look into a long-polling or "comet" architecture. This is widely used by event driven AJAX applications and will provide what you are looking for.
See https://en.wikipedia.org/wiki/Comet_(programming) for more info.
I need a way to count how many times a link is being clicked and I was thinking of creating a php script to redirect to and do the counting. Is there a better way to do this and how would i count each time the user visits the link and would it be best to save in the database somewhere...any suggestions
Yes, it must be a PHP script - JavaScript for example won't work all the time.
So - instead of a link to
http://some.site.com/page2.php
You would link to
http://some.site.com/redirect.php?page2.php
And in the redirect.php you will track, for example, in a database, the values, and in the end throw this header:
header("Location: http://some.site.com/".$_SERVER["QUERY_STRING"]);
To redirect to the path after ?...
// yeah - logs might work... a little bit more work, though and it is also very server specific.
I would analyze your web log files as this will work whether it's a static page or a script.
If the page you need to count is a script, you could insert code that updates a table.
Website statistics is a big industry and there are many free and pay solutions out there to explore and get ideas from.
If you need to track clicks on a specific link then you'll probably need to use javascript to capture the click and send a notification to a tracking server. If you need to track page views then you're best off looking at your server logs. Remember that a page can have many links pointing to it, you have to differentiate between link clicks events page page impressions. Another possibility, depending on your application, is to use Google tracking, or a similar third party tracking app.