Progress bar showing database progress - php

I was wondering, since I'm making a GPT Script, I need an installation system to insert database queries, and create tables.
I know how to do that, but the problem is I want to show the progress of creating files, registering the product to my server, with a progress bar, so the user knows how much longer they'll be waiting.
How can I do this?

PHP runs server-side, jQuery runs client-side. You would have to call a server-side script repeatedly, either to check the number of rows that have been inserted or tables that have been created, etc...or to tell it to perform another step, updating your progress bar on each call.
Either way is a performance hit, so probably not a good idea.

Related

Performance: Loop incl. AJAX vs. a single request with php loop

I wrote a PHP that is currently looping through data, validating and importing them into a database. This can take some time, depending on the amount of data to run through.
My next step is to make this "user-friendly" so others can use it, not just me. I was looking at the components I want to implement, including a progress bar so the user knows the script isn't just stuck but is doing something.
Now the question comes up: should I use a JavaScript loop through the data, have them validated one by one and imported to the database with the help of an AJAX call to my php script? This would be pretty useful as well to update the progress bar after each iteration.
Or is it—performance-wise—better to do a single request to the php script which then loops through the data? In that case: how could I implement the updating progress bar?
These are a bunch of questions. The overall purpose is to see what my options are and what arguments speak for each. Thanks in advance!
Well if you want to have a progress bar, then you will need to do it 1-by-1, you would count all the records and then very time one calls back as completed, you would increment the progress bar by a certain percentage.
100 / amount of records = percentage to increase progress bar.
However, the issue with that approach is that if somewhere along the line it fails, you will need to know where it did so, or devise a way to make sure duplicates are not added to the database (If that's even an issue).
It would be better to add the data at once, faster and cleaner, but it would remove the possibility of having a progress bar that actually gives you a correct progress report.

MySQL & webpage: Notification on insert in table

I have an application on a server that monitors a log file, I've also added a view at the client side (in the form of a website). Now I would like to implement the following: Whenever a new entry has been added, the view should update as fast as possible.
First I have thought of two practical solutions:
1) Call an AJAX function that requests a php page every second, which checks for updates, and if so show's them. (Disadvantages: Lots of HTTP overhead, a lot of the time there may be no message, lots of SQL calls)
2) Call an AJAX function that requests a different php page every minute, which also checks for updates for 1 minute, but only returns if it has found an update, or else after 1 minute. (Disadvantages: HTTP overhead, but less as option 1, may still have times without message, still a lot of SQL calls)
Which of those ones would be better, or what alternative would you advice?
I have also thought of yet another solution, but I'm unsure of how to implement it. That would be that on every INSERT on a specific table in the MySQL database, the webpage would directly be notified, perhaps via a push connection, but I'm also unsure of how those work.

PHP jQuery MySQL refesh instant

I have made a progress sheet that between 1-30 users will update constantly throughout the course of the day. It’s controlled by PHP and jQuery and all the data is stored in a mySql database.
It’s quite slow on the live server, because I re query on searches and filters. I was wondering where is the best place to store the result, because I only need the latest updates but I do not need to constantly filter and update.
Is it okay to store that kind of data in a session or who else could I store it to avoid full query on every change/search or when the page changes?
I did look into memcached, but I ended up redesigning it.
I used jQuery to filter the records using hide() and show() on the data attributes that matched, instead of using a “LIKE '%Darren%'” SQL query.
This puts the load on the user’s terminal opposed to my server (Try to keep the animations to a minimum, to keep the memory usage low).
Then I store a timestamp of the last update on the user’s terminal in the HTML then run a
“SELECT id FROW progress WHERE updated > '2014-02-20 16:54:30' LIMIT 1” query periodically.
If I get 1 record back I use Ajax to a full update and refresh the areas required with fresh HTML.
Doing it this way has made it so much quicker and smoother.
I how this helps, if you need more info let me know!

What php function to use to pull data from MySQL periodically and display it on website?

I'm running a server and website for an online game.
I need to pull information from the mySQL database containing player names and messages and display it on our website.
I managed to do that with a php script which directly pulls the info from the MySQL database whenever someone opens the page.
However, this puts unnecessary load on the server.
I need to achieve so that the function pulls the data only at certain intervals, for example, every hour.
I have no idea how to do this and what to even look for in terms of functions.
Could anyone show me the right direction?
If you're worried about the load being placed on the call being made every time the user opens up the site, perhaps first you should look into caching. Something like APC or memcached, that way there isn't an actual DB lookup, it just returns the same data that it grabbed last time You just set the period that you want the cache to hold the data so that in time it will grab a fresh copy, in your case this would be an hour.
There's a bunch of questions on APC, memcached etc on stack overflow that should be able to help you out, e.g., The best way of PHP Caching

DB operation, Is it very expensive?

I have table called playlist, and I display those details using display_playlist.php file.
screen shot of display_playlist.php:
Every time user clicks the 'up' or 'down' button to arrange the song order, I just update the table.But I feel updating DB very often is not recommended, so Is there any efficient way to accomplish this task.
I am still a newbie to AJAX, so if AJAX is the only way to do it, can you please explain it in detail.thank you in advance.
In relative terms, yes, hitting the database is an expensive operation. However, if the playlist state is meant to be persistent then you have to hit the database at some point, it's just a question of when/how often.
One simple optimization you might try is instead of sending each change the user makes to the server right away, allow them to make however many changes they want (using some client-side javascript to keep the UI in the correct state) and provide a "Save Playlist" button that they can press to submit all of their changes to the server at once. That will reduce database hits, and also the number of round-trips made to the server (in terms of what a user experiences, a round-trip to the server is far more expensive than a database hit).
More broadly though, you shouldn't get hung up over hypothetical performance concerns. Is your application too slow to handle its current load (and if so, have you done any profiling to verify that it is indeed this database query that is causing the issue)? If not, then you don't need to worry too much about changing it just yet.
You can have a save button, so instead of updating on each move there will only be one update where you update every row at one time. This also lets you have a cancel button for people to refresh the way it was.
You can do it so users can change locally all they wish; defer writing the final result to the database until they choose to move on from the page.
if you really want to avoid updating the database, you can try some JavaScript based MP3players , which allow you to pass the path to *.mp3 files.
Then I suggest you to use Jquery UI - Sortable
and use it to update the songs list to the flash player ..

Categories