Refresh page and parallely analyze mysql - php

I am working on e-commerce project. Book Section has 60,000 books and 37,000 authors in my mysql tables.
here is the link of book table structure
Book page takes 13 seconds to load-Horrible. I want to know that is there any tool that Give me real time analysis. It mean, I refresh page and I can see total number of queries executed when page load completes. So I can analyze and write time effective queries.
Additionally, Please guide me little for how can I improve mysql performance for such e-commerce project. Project's Index page displays 3-4 items from all section like camera, Apparels, Mobile etc. So in turn fetch from almost all categories.
Please help.
Thank you In advance.

Are you limiting your result set of the data returned? Please remember to post the query that you are running.

Related

Php : Avoid database queries for each visitors

Today multiple questions came to me about how web servers work with a basic code of request in database and display to the front.
For the example of a blog where we want to display our posts
I don't know any other way than
Query the database then stock the result in a php variable
Foreach the variable in the front to display the different contents
as simple as that but the question is :
Does the database query each time a visitor browse the web page supposed to display our posts ?
For me it has always worked as this. But now I'm asking myself why do we make requests on a table that we (the writers of the posts) update like one time each week everytime we visit the page ? In the case of a blog with thousands daily visitors while we update it every week, Do we query the database that much time ?
The question is the same for the php process that "foreach" every posts which require a little bit more process for the server before displaying the web page. Multiplied by the number of visitor.
If it really works as I think, how do we avoid all of these ?
Its sounds like you want to use Caching - there are simple ways to do this, and libraries/products that can help you see this article and this library

Building webpages that are indexed for mutiple items and such

I'm moreless curious about webpages that are indexed. An example is gamestop. When you are looking through their product lists they have indexed for multiple tabs like 123456 on the near the bottom of the page. I also notice this with many search engines and pages selling products. I know it sounds dumb to ask a question like this, but I've always been curious how to code a mutiple indexed page like the example listed above. I hope you fellow coders out there could provide some sample code to demonstrate this idea would be perfect. Plus, it could help me in future to see just how it is done. Please provide any info you can. Thank you :)
Actually the INDEXING you are referring is called Pagination. Whenever you have multiple items/Records and you want to show only some of them in one page and rest on the other. e.g. you have 100 records in the database and you want to show all of them but loading all at once will slow down your page. So what programmers do is, they use pagination.
What they do is , They will show first 10 records on one page. if you have 100 records in database. Then first page will show records from 1 to 10, 2nd page will show 11 to 20 and so on till the end.
use reference
http://code.tutsplus.com/tutorials/how-to-paginate-data-with-php--net-2928
or
Simple PHP Pagination script

Is php pagination compulsory?

sorry if the question seems too idiot. I am student in development. I created a complete php website for posting stitches (with image video and audio) and then retrieving other users opinions on posted stitches. I made mobile ready and all. But I forgot to set pagination while building it. Yes that was not smart at all. Somehow I still don't have any issue with the website cause there are only 20-30 entries in the database. But in the future if I get more entries, will it freeze browsers considering the fact that there is no pagination for limiting query fetching. I'd like you to tell me what will technically happen if I don't set a pagination system.
If it is compulsory to set a pagination system, can you point me a very great and simple pagination tutorial !?
Thank you
EDIT: Ok, thank you for answers, I will set a pagination system for better user experience. Once again, thanks to all of you !!! 😊👍🏾
RE-EDIT:
I did it !!!!!!! I used Ajax. Added a load more button button and refreshes div via Ajax. Merci !!
Pagination plays a very important role in performance and user experience. As you are hitting to database and fetching more rows uses more memory which can slow database. On the other hand browsers can crash with a lot-of records. specially when you are making web services for mobile devices. So it is good practice to use pagination in php to avoid such overhauls of browser and database or any mobile device etc.

How does one add banner advertisement like facebook?

What I am trying to do is give companies an option to show their ads on my website, like how Facebook does. I have a user based website, so there are many different pages.
If I have to guess, it would go something like this.
Step 1. Company creates an Ad(with different payment options).
Step 2. The Ad is added to a mysql table.
Step 3. The Ads are shown across the website, depending on the algorithm.
Now I would need to know a more detail way of doing it. Are there any good resources I can study?
Well, you have multiple options. The easiest is to just use an existing ad-company like Google AdWords. Just just create an account there, embed their code in your site and you're finished.
The point is that creating your own ad-engine brings several problems:
You have to write the engine, including payment options, click tracking etc
and care about legal problems and contracts (a company may sue you for not displaying ads enough, caused by bug or misinterpretation etc)
Also you need to find someone who advertises at your site
AdBlocker
It's not impossible and embedding a static image won't bring to much problems, but for totally automating the engine you'll have to worry about all those problems, especially the legal ones. If you still want do this, look at 4chan's AdEngine:
Let the advertiser upload an image and store it on your server, save the click or view count left in the db.
When a site with ads is loaded, query the db for ads where count_left > 0 (order by random is an option, as it usually balances at many queries) and display the corresponding image. If your site has different categories, you may want to add a tag-clause or something. Also, set the view count down by one. If you intend to use click count, let the img's link point on your website and subtract the clickcount, but watch out that it isn't called multiple times by a single client to damage your customers (per-session or per-ip lock).
Hope this helps; I'd recommend you AdWords as it saves a lot of trouble and work.

PHP displaying page views for gallery style pages

This is really a point me in the right direction question. What path should I take if I want to display the number of page views each gallery page receives?
Retrieve Google Analytics Data via PHP, or
Capture the page views directly on my pages with my own PHP and mySQL setup?
Seems, like number 1 would be the better choice. I just don't know how difficult this option will be. Any insights on this?
Option 2 is definitely simpler.
If you do figure out how to get the page results out of Google Analytics, they will not be up-to-date. It takes Google at least several hours before the page views show up.
That also depends if You want to have info on more questions (statistics). I often use custom setup to track such things cause I can later use some data to do statistics about users actions.
For example, You want to give users (owners of photos) info about witch users (male or female, 30+ or below 30, and so on) are viewing. How many guests, how many registered users. There are tons of data You can retrive by building custom system.
It all depends on what You want to have at the end.
I suspect that if You want to have only raw data about number of users You coud somehow parse data from Google Analytics as well.
And as posted below. Google have to take time to update, custom setup not.

Categories