How update page on server automatically while my laptop is off - php

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

Related

force reload/refresh a second webpage through php

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.

Creating A Website Status Page

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/

How to create a small widget to display data from remote server using PHP Mysql

I am looking to build a platform which will allow users to add timings on the user section and then they can add few codes to display the time on their website.
So far I have completed the back section using PHP and Mysql where users can add/update timings.
Now I am stuck for the front panel.
Two things to know that this widget kind of thing will be displaying to their website so I have to setup remote connection to database on my server obviously without giving database credentials to the users.
I am new to PHP and didn't know till today that "Include" only works for the local server so I can't include my database.php which holds mysql credentials.
If you go on this website http://islamicsocietyoftoronto.com you will notice prayer time on right hand. This is actually I am trying to replicate.
Any help would be really appreciated.
You put the URL to your timer in an <iframe> that your users can put on their page.

Display realtime user status using AJAX and PHP from a MySQL database

I have a simple mysql query which shows users last status. I now want to go further and create a page to show users most recent status without refreshing. The mysql DB is dynamically updated with the users status.
So all that is required is for the page rendering the mysql to refresh with the latest user status without me having to hit the refresh button.
Could anyone provide guidance on how I go about doing this. Thanks
You need push into page, not pool. It is kind of stupid to do poling from database.
Here is how that works.
Let asume that you have n users on you page.
Every time that status is changed (you insert that into you DB)
2.1 As this happens you need to push signal to your webpage (use Strophe library).
2.2 In order to push something to page you need Strophe instance running.
2.3 If your website is PHP, here is good class for communicating with Strophe instance.
I can do this for your but you will be more happy if you do this on your own.
That real time stuff are very interesting.

PHP Instant Messages Update

I am creating a messaging system which have the following parts:
A form which send user message and upon submission of the form, PHP inserts the data into a MySQL Table called userMessages.
A PHP page which performs a MySQL Query select all from userMessages and displays all the messages.
The problem I'm having is making this messaging system have an INSTANT Message Functionality. i.e. I submit data from one form and it instantly appears on the user messages page WITHOUT having to manually refresh the page.
I do have temporary solution of refreshing the page every 20 second. But is there a way to update the messages page only at the moment a new message is submitted?
Pushing data to a web page is very hard, as Dan Grossman has said you will want to read that wiki article. AJAX polling every few seconds would be a good idea, if you don't mind a rather high server and database load. ama2 is also right - PHP is inherently not the best system for this, and a continuously running application server using, say, node.js, may be a lot more efficient.

Categories