PHP code seems too slow for the database? Any ideas?
Moderator: General Moderators
PHP code seems too slow for the database? Any ideas?
would Java handle it faster? can PHP be made to handle it as fast? I really need help.
check out my website and search cars for sale, then any distance and then 37919 zip. it takes too long and there are only 3351 cars on there now. before, when it only had about 2200 cars it was really fast. only about a 1000 cars made it slow. what could it be? nabacar.com It was returning results in about 15 seconds or less with 2200 cars. Now it is over a minute with only 1000 cars on it. I will have 150,000 on it when I get this sorted.
http://nabacar.com
some java was written to speed things up, but it didn't seem to help. Is it the server or the code causing this?
check out my website and search cars for sale, then any distance and then 37919 zip. it takes too long and there are only 3351 cars on there now. before, when it only had about 2200 cars it was really fast. only about a 1000 cars made it slow. what could it be? nabacar.com It was returning results in about 15 seconds or less with 2200 cars. Now it is over a minute with only 1000 cars on it. I will have 150,000 on it when I get this sorted.
http://nabacar.com
some java was written to speed things up, but it didn't seem to help. Is it the server or the code causing this?
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP code seems too slow for the database? Any ideas?
I believe it could be either way. It could be a grossly inefficient search mechanism, or the server could be really really wimpy. In fact, thinking about it, the former seems like it would be the most likely.
The speed advantage of using Java would be negligible.
The speed advantage of using Java would be negligible.
-
JoeCommodore
- Forum Newbie
- Posts: 15
- Joined: Fri Oct 01, 2010 10:16 pm
Re: PHP code seems too slow for the database? Any ideas?
The main thing I found for speeding up my databases is
1. get as much done as you can in the db query, MySQL (or whatever flavor) can extract and manipulate data a whole lot faster than PHP, a 100 line queery in MySQL is better then a 100 line list processor in PHP.
2. Index, index, index. Index as many of the fields as you can that are part of your query, this makes a HUGE difference.
1. get as much done as you can in the db query, MySQL (or whatever flavor) can extract and manipulate data a whole lot faster than PHP, a 100 line queery in MySQL is better then a 100 line list processor in PHP.
2. Index, index, index. Index as many of the fields as you can that are part of your query, this makes a HUGE difference.
Re: PHP code seems too slow for the database? Any ideas?
after looking at the site, do you think that PHP should be able to handle that kind of data? and much much more? maybe 250,000 cars?
Re: PHP code seems too slow for the database? Any ideas?
also, what is index? I am trying to find out this stuff for the developers. I catch on quick
Re: PHP code seems too slow for the database? Any ideas?
is there a way I can test the script using a program? run each one through and see if there are any problems?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: PHP code seems too slow for the database? Any ideas?
Post the slow query, the table structures, and then run an EXPLAIN on the queries and post the results of that too.
[text]
EXPLAIN your_query_here[/text]
[text]
EXPLAIN your_query_here[/text]
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP code seems too slow for the database? Any ideas?
PHP can handle 250,000 cars just as well as it can. The reason is, (theoretically) it doesn't have to deal with it all. That is what the database and SQL are for. The exception would be if you are looping through every item in the database, and I think that would be pretty bad.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: PHP code seems too slow for the database? Any ideas?
In in your private message reguarding how to identify the query..
The easy way would be to open up your PHP file and for the SQL that is performing the actual search.
Otherwise, you might want to enable Slow Query Log, although I think that is too advanced for you at the moment.
The easy way would be to open up your PHP file and for the SQL that is performing the actual search.
Otherwise, you might want to enable Slow Query Log, although I think that is too advanced for you at the moment.
Re: PHP code seems too slow for the database? Any ideas?
I have read a lot of books on php and I still find it really hard. but.... I will try what you are telling me. I have got to find the bottleneck or at least see if there is one.
Re: PHP code seems too slow for the database? Any ideas?
did you try a search with any distance and using 37917 zip? you don't have to check anything else, just those two things and look how long it takes.
only a thousand more cars bogged it down. it was so fast until I added the cars.
only a thousand more cars bogged it down. it was so fast until I added the cars.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: PHP code seems too slow for the database? Any ideas?
Why don't you try posting the script that performs the search, and I'm sure we will be able to identify the query performing the search.
Re: PHP code seems too slow for the database? Any ideas?
I am going to look for it now. it is a huge jumbled mess to a non-programmer lol
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP code seems too slow for the database? Any ideas?
<mutter>
It's probably a big jumbled mess. Period.
</mutter>
It's probably a big jumbled mess. Period.
</mutter>
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: PHP code seems too slow for the database? Any ideas?
How are you calculating distances? Do you select the entire table into PHP memory then iterating and calculating distances using a PHP algorithm?
It might make sense to move that calculation into a stored proc and exeucte the search based on criteria. A stored proc in this case, would probably run faster than a similar PHP algorithm.
Also, check your indexes.
It's difficult to determine what you should do without seeing your implementation. I assume your taking the zipcode, fetching a lat/lon coordinate and locating all records which are within a distance specified by end users? You would then have to select all records, iterate each one and calculate the distance and conditionally drop those which are outside the regional boundries???
If this were the case, I would probably move that algorithm into a stored proc.
Cheers,
Alex
It might make sense to move that calculation into a stored proc and exeucte the search based on criteria. A stored proc in this case, would probably run faster than a similar PHP algorithm.
Also, check your indexes.
It's difficult to determine what you should do without seeing your implementation. I assume your taking the zipcode, fetching a lat/lon coordinate and locating all records which are within a distance specified by end users? You would then have to select all records, iterate each one and calculate the distance and conditionally drop those which are outside the regional boundries???
If this were the case, I would probably move that algorithm into a stored proc.
Cheers,
Alex