59 Replies - 11603 Views - Last Post: 20 June 2012 - 06:30 AM
#1
php good choice?
Posted 15 June 2012 - 02:33 PM
cheers
Nick
Replies To: php good choice?
#2
Re: php good choice?
Posted 15 June 2012 - 02:36 PM
#3
Re: php good choice?
Posted 15 June 2012 - 03:54 PM
Quote
Usually, with something like a CMS (which is going to be reading/searching/updating a database), this is an indication of a poorly-tuned database.
#4
Re: php good choice?
Posted 15 June 2012 - 04:03 PM
#5
Re: php good choice?
Posted 15 June 2012 - 04:35 PM
#6
Re: php good choice?
Posted 15 June 2012 - 04:57 PM
#7
Re: php good choice?
Posted 15 June 2012 - 06:12 PM
Every sql query they make is like
$query = mysql_query("SELECT `id` FROM `enq` WHERE `status` = '1' AND `assignedto` IS NULL ORDER BY `date` DESC");
I remember someone the other day saying prepared statements should be used instead. This management system is very database driven, so would changing all the quiries into prepared statements have an impact on speed?
Nick
#8
Re: php good choice?
Posted 16 June 2012 - 02:42 AM

POPULAR
Here's the question: for this particular query, is there an index on the status and assignedto fields for the enq table? That would improve SELECT performance (while decreasing INSERT/UPDATE performance slightly). Those are the sort of things database tuning can assist with.
#9
Re: php good choice?
Posted 16 June 2012 - 04:04 PM

POPULAR
nick2price, on 16 June 2012 - 12:12 PM, said:
Without knowing what your application is doing, just that it is a CMS, 20 users should not be a problem. The fact that it is written in PHP shouldn't be a problem either - AFAIK Facebook, Wikipedia and Yahoo are all in PHP.
Quote
Yes, and the impact is hard to measure. For starters, there are 3 trips made to the DB when you first prepare a statement (I believe) - one to prepare the statement, one to check the parameters, one to retrieve the results. Depending on the sort of queries you're firing off, and how often you are firing off the same parameterised query, it could result in better performance or worse. Still, the upside is that you get security against SQL injection.
Also, there are a lot of instances under which a prepared statement will not get cached. If you are using MySQL < 5.1.17, there will be no caching. If the statement contains certain commands (such as CURRENT_TIMESTAMP(), UNIX_TIMESTAMP(), RAND()) it will not be cached. If it refers to functions or uses temporary tables it will not be cached. The full list can be found here.
JackOfAllTrades, on 16 June 2012 - 08:42 PM, said:
JackOfAllTrades raises a very important, if not crucial, point here. Assuming you are using the INNO_DB engine (and that you are using MySQL, rather than say PostgreSQL) have you indexed up the tables? Indexing can make a world of difference. At my work we use MSSQL, and we had one query that took 2 minutes to run. We applied one index, albeit to 6 columns, and the query execution time dropped to about 500ms.
My advice, if you are new to optimisation of SQL, would be to have a look at this slideshow. It goes through a lot of the common optimisation techniques, and talks about query structure, indexes, normalisation, architecture, and prepared statements. Excellent read in fact. As for specific advice, there are hundreds of optimisation techniques I could tell you about, but it's easier to go through them on a one by one basis. Using EXPLAIN in MySQL, or simply stopwatching query times can tell you where you have slow queries. Slow queries mean either bad queries, bad normalisation, bad indexes, or a genuinely hard-working query. It's usually one of the first three.
This post has been edited by e_i_pi: 16 June 2012 - 04:06 PM
#10
Re: php good choice?
Posted 16 June 2012 - 04:13 PM
Quote
As e_i_pi touched upon, the real performance gain with prepared statements is that they work similarly to functions. Because they are cached on the SQL server, you can pass new parameters and the statement will fill them in. So the more you use the query, the more efficient it is over not using prepared statements.
#11
Re: php good choice?
Posted 16 June 2012 - 05:20 PM
But yeh, to the OP, very rarely is a language to blame, it's usually the programmers terrible design that causes the biggest problem. The fact that they used 'mysql_query' shows their inexperience unless this was written years and years ago.
Another note to add is that PHP was designed for the web, unlike other languages such as Python and C etc. So everything is taken into account for the web. The only other alternative that is solely web based is ASP as far as I'm aware, but that's Microsoft's attempt at a web based language, because as always, another language isn't good enough for them.
Before someone tells me that PHP can be used for desktop applications, this was not it's original purpose, but I am aware of this.
This post has been edited by mccabec123: 16 June 2012 - 07:43 PM
#12
Re: php good choice?
Posted 16 June 2012 - 06:38 PM
mccabec123 said:
That's not really something you should be taking into account when choosing a language, though. The fact that PHP is pretty much solely intended for server-side web development does in no way mean that it is somehow better suited for the task, or more efficient at it, than other languages with a broader range. Languages like ASP.NET, Java or even Python don't suffer one bit in the web development area because of their support for other types of programming.
#15
Re: php good choice?
Posted 16 June 2012 - 06:57 PM
|
|

New Topic/Question
Reply



MultiQuote













|