Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am working on a project for a client to make their roster viewing and entry paper-free. Some things rely on user input, but others are varied constants and are pulled from a database. One of the dropdowns pulling its information from said database is loading very slowly in my testing environment - I click it, and it takes two to three seconds for the items to actually show up.
I assume this is because the dropdown contains easily close to 400 items. What I'd like to know is if there is any way I can optimize this to make the loading faster. Cutting off at halfway or even a fourth of the way and making more dropdowns is outside of specification for the project, so a suggestion like that would have to go through the client for the go ahead. If that's the only solution, though, I'll do that.
Thanks in advance for suggestions.
EDIT:
This is the kind of oversight that makes me laugh, but I was wrong about my conservative estimate of 400 items - the list contains 12,700 items.
For all who assume the SQL query may be slow - I am doing a simple SELECT DISTINCT from one table, with only one WHERE condition.
Before this question can be answered well, you'll need to do more testing and debugging to figure out what exactly is slowing things down.
Is this just a problem with your machine running something slowly?
Test things out on a real webserver and see how things go.
Is the select from the database slow? If so, that's a problem,
selects from mysql should be really fast.
Is the php slow? If so, you can use an IDE like PhpStorm to see
exactly what functions take how long to run.
Is the rendering in the client browser slow? If so, we can look at
optimizing the javascript/html.
As noted in a comment above, we also need to know when you are getting data from the database (before the page loads, or ajax). So before you can really look at how to speed this up, you need to know what is taking so long. Start there. Also make sure to check your javascript and html for any errors. Copy/paste the entire page's html into here, and fix all errors and warnings: http://validator.w3.org/#validate_by_input For javascript, check the debugger console.
You could use an infinite scroll to break up the amount of data being returned. Take a look at this answer:
infinite scroll select
This may not be the underlying issue though. I would check the performance of your query to ensure that is not where the issue lies.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I just have a general question. I am concerned with the speed of my PHP website, which is set to go into production soon.
My concern is the length of time it takes for the page to run a query.
On my page, I have about 14 filters in an HTML form. I am using the method GET to retrieve all the values from the filters. Granted, not all 14 filters have to be used. A user can just search off one filter. Of course, the more filters are selected, the larger the query becomes. But the larger the query becomes, the quicker the page loads. So it's beneficial for the user to select more filters over using just one filter.
All of the filter values are then sent to an INCLUDED PHP file, which then builds a query based off of the user's filtered selection.
The query runs and I am able to print the selected data into an HTML table on the original page. The problem is the it can take quite some time for the page to render and finally display the data-table.
The database is not too large. Maybe between 20K - 40K records, though there are over 20 columns per record.
When I run the same query in MySQL, it returns the data faster than it does on the page.
Here is where I believe the problem might lie.
Within the form are the filters. About 5-6 of the filters are running queries themselves to populate the selection data for the user.
I believe that after the user runs a query, the page refreshes and it has to re-run all the filter queries within the form.
If this is the case, what steps can I take to fix this issue? If any. Should I place all of the filters in a separate file and INCLUDE them within the form? If not, then please advise what I can do to speed up the page loading process.
I have visited various websites in an attempt to fix this issue. Like this one:
http://code.tutsplus.com/tutorials/top-20-mysql-best-practices--net-7855
I am following just about every step suggested by that site, but I am still experiencing the page load delay.
I hope I can receive some positive insight.
Thank you in advance.
What you can do is if all the filters are static and do not disappear or change view when selected / changed value you can set the filters outside of the reload view.
Currently I am building a site that is dealing with AJAX query reload and have to deal with a very similar aspect. My fields are set outside of the reload and I have very fast load times.
If they are dynamic or need to change based on options chosen then I would set them as a separate reload. Basically determining which ones changed vs what needs to be displayed.
Hopefully this helps and explains well enough.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a fixed (rarely changing) list of ~100 words. I want to display a random word on my HTML page on every reload. Should I hardcode the words as an array in the PHP script, or should I put them into a MySQL table and pull a random entry from there? What are the possible performance/maintainability considerations here?
It depends, if you ever want to easily manage these words or have someone else manage them, I would go for putting them into a database. Using a database has an extremely high overhead relative to a PHP array, although it is likely unnoticeable for a human if hosted locally.
I would not use anything other then a PHP array, database table, or text file though. I think that even a text file is a little bit extraneous and shouldn't be used - if you would want it in a text file it's probably just best to put it in a database.
My take is that it depends on these factors:
How rarely is "rarely"? Like once every year? Or maybe once every month?
How many requests are you getting, and how many are you predicting?
Do you have an established development/deployment cycle? Meaning, steps between changing some code and actually updating in production servers.
Do you have direct access to the databse? Or would you have to set up and admin tool in order to edit the list?
I would favor a non-MySQL scenario if you don't use the DB for anything else, or if you are getting millions of requests per day, so as not to add millions of queries for such a simple objective. Maybe using a local file with the words would suffice, if you have relatively straightforward access to the filesystem.
I wouldn't go for MySQL as its just not needed for a non-changing set of words. If you plan to change them whatsoever go for a CSV file [using implode() and explode() to manage it] or if you are very rarely or never changing them then a PHP Array would be best for performance, with 0 maintenance.
If you wanted to change the words via a nice interface you were going to write, I'd store them in MySQL. If they rarely change and it's just as easy to update your code as it is the database, then you might as well just store them in a PHP array.
I will say to use hardcode as php array instead of mysql and other connectivity part for these so it will be easy and you are saying you will use it rarely.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
coinbase.com
1. Class = top-balance
Cex.io
2. Id = ticker-GHS-BTC-price
3. Id = ticker-FHA-BTC
4. Id = ticker-FHM-BTC
at a 1 min interval then take 1 and multiply it by 2,3,4 to create separate values then multiple each by 50 then make a db entry.
Im a complete noob with php.. much thanks!
I don't know how you're getting the information from Coinbase or Cex.io, but if it's an XML feed try learning SimpleXML. It's a great tool for PHP and makes things really easy to manage. Then you can find the entry you need and assign it to a variable.
It would really help if you provided some URLs for the data feeds. If you're planning on scraping the webpage itself, please, PLEASE try to find an API first. I made that mistake when I was starting out. An API will give you a URL of just XML or just JSON usually. Either way with basic PHP tools like SimpleXML you can turn these into arrays with all your data.
As far as the math parts, just use your basic math symbols. They work the same as most lanugages:
multiply by 2: $variable_x2 = $variable * 2
If you're dealing with a lot of multiplying, try a for loop and make an array.
If you're going to put these in a database, I'll assume you're using MySQL. That's one of the most common database formats. Make sure that all your tables, etc. are set up before trying to write to them. If you're new to MySQL too, use a utility like PHPMyAdmin, which will make the process of setting up much easier. It's pre-installed on most webhosts.
Now for the whole "one minute intervals" thing. Either you're going to have a loop with some wait time and keep the page open on infinite load, which I don't recommend because it makes some web hosts mad, or you're going to use CRON. Most hosts I deal with have a simple CRON setup: you specify the file to run and how often to run it. I don't know how you're set up though.
This should get you started. If you want to revise your question with more information on your issues and how your host is set up and how you're getting your data, I'm sure we can help a lot more. But as a starter try what I've mentioned. PHP.net is your friend: look up ANYTHING you don't understand!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i have a blog system which has articles inside a database, now i want to build a feature where it displays five of the most popular articles in the database, according to how many views it gets.
Is there any sort of technology out there which i can take advantage of where it states how many views a page has received, and IS able to be integrated into a database.
Or perhaps there is a better internal method of doing something like this?
Thanks in advance.
EDIT: If you are going do down vote my thread randomly, at least tell me why.
You have three choices as an approach for this obviously:
you collect the usage count inside your database (a click counter)
you extract that information from the http servers access log file later
you could implement a click counter based on http server request hits
Both approaches have advantages and disadvantages. The first obviously means you have to implement such a counter and modify your database scheme. The second means you have asynchronous behavior (not always bad), but the components depend on each other, so your setup gets more complex. So I would advise for the first approach.
A click counter is something really basic and typical for all cms/blog systems and not that complex to implement. Since the content is typically generated dynamically (read: by a script) you typically have one request per view, so it is trivial to increment a counter in a table recording views of pages. From there your feature is clear: read the top five counter values and display a list of five links to those pages.
If you go with the second approach then you will need to store that extracted information, since log files are rotated, compressed, archived and deleted. So you either need a self tailored database for that or some finished product. But as said: this approach is much more complex in the end.
The last option is nothing I saw, it just sprang to my mind. You could for example use phps (just as an example) auto append feature to run a counting routine in a generic way. That routine could interpret the request url, decide if it was a request to an article view. If so it could raise a click counter, typically in a small database, since you might have several requests at the same time, which speaks against using a file. but why make things that xomplex? Go with the first option.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
My boss asked me to create a easier system for finding points by having points associated with the user table in our mysql database. The old system just had events, there point values, then another table with events completed for a user, and then another table for just admin given points. So my job was to add these all together and put them in a column. Now he says the problem is that there is still all the queries running around adding points, but instead of changing them to simply add points to the users column upon task completion, they suggested i use a trigger to simply add points to the users column, when one of the other columns has points added to it.
To me this sounds like using a work-around and creating technical debt. Am i wrong?
Im new to the system, and i dont know exactly where all the queries are in the php pages, but if this is creating technical debt, what would be the appropriate way to fix this.
Im new and am probably going to just use sql triggers as to not go against my boss's suggestions, I want to at least know the smart/best way to do things.
Doing my best to provide not actual, but near actual db schema
EVENT: ID, point value, Desc
User-Events: USERID, EVENTID, COMPLETION-STATUS
GIVEN-POINTS:USERID, POINTS_GIVEN, DESC (Each time points are given, so its more of a log than updated points)
I added a Points column to the basic USER TABLE
the trigger would be when user-Event completion-status =done, find point value, add to points in user, instead of changing queries to do that.
Triggers are a perfectly valid way to accomplish what you are trying to do, as long as the business rules are fairly simple.
There are lots of ways to accomplish moving data from one table to another. You can use triggers, some sort of synchronous PHP process or an asynchronous process using some sort of message queue.
Triggers have the benefit of being simple and fast to code, maintain, and run. The upside is that you only have to do the code once, which is especially nice since you don't know where all the queries that touch these tables are. The downside is that you could be putting business logic into the database, which is where you might start getting into technical debt. The other downside is simply that you've added another business layer, which might not be obvious to the next developer, so they might spend a lot of time trying to figure out how and why the summary table is being updated. Comments are a good thing, in this case.
Synchronous PHP processes are are nice in that it's very obvious where the code is being executed. The other upside is that you have access to the whole PHP application context and can create more complex business rules. The downside is that you will have to put the function or method call into each place where the table is potentially being touched.
Asynchronous PHP processes have the same up and downsides as the synchronous PHP processes, with the added benefit that they aren't going to slow down the user experience. They are also a little more complex to create; you have to handle cases where the messages aren't received, or aren't received in the correct order.