Profiling PHP

I've just added profiling to my base class so it can show me how my views and models are running. Straight away a surprise. mysql_connect takes nearly as long as selecting a page of rows from a table. Apparently connections to other DBs are even worse. http://www.mysqlperformanceblog.com/2006/11/12/are-php-persistent-connec...

Is PHP a toy programming language or a fully fledged enterprise-ready professional programming language?

Toy
100% (1 vote)
Professional
0% (0 votes)
Total votes: 1

When does str_repeat() fail?

When does str_repeat() http://uk.php.net/str_repeat fail? ... when the second parameter is negative. So if you are calculating the value of this parameter you need to check that it is greater than or equal to 0 yourself or handle the error manually.

Strangely the str_repeat() page says nothing about this error condition, just thet the second parameter must be >= 0. If this was to be consistent with formatted number handling http://www.greg-wright.co.uk/node/14 then PHP should just ignore the problem and return an empty string.

PHP is a bug factory

Suppose you unknowingly treat a string containing a formatted number, like "1,234.56" as if it were a real number. What would happen?

Common sense would say that PHP should do one of 2 things, either ignore the comma, or throw up its hands and complain about the number/string you've given it and, most importantly, stop.

However it doesn't do that, it simply ignores everything from the comma, so your 1,000,000 pounds becomes £1.
This can happen all too often if programmers abuse the number_format() function.

jQuery saves bacon

Just imagine the scenario, the Sales Manager comes along and asks you to fix a form that is broken, it's urgently needed, and some check boxes displayed on the form are not working. Sounds straightforward so you agree to take a look, then the nightmare begins ...

PHP Anti-patterns 1: The Bug Factory Anti-pattern

I recently found a PHP function with 32 parameters. Not the first time I've seen one of these.

Long parameter lists like this should probably be avoided. Here are some of the issues:

If we guestimate conservatively that the probability of getting one parameter wrong without noticing is 1% i.e. 0.01, and we assume that the probability is independent between the parameters, then the probability of getting the whole parameter list right is 0.99^32 = 0.725 i.e. the probability of getting it wrong is 0.275 i.e. more than 25% of calls to this function will be wrong.

Lesson learnt

Running the following query:

SELECT orderId FROM orders where orderRef=737357947879;

Was taking 2 seconds, despite the key on orders.orderRef
Explain showed it was ignoring the possible key and FORCE INDEX did nothing.

It turned out that orderRef was a varchar (This was not my schema I hasten to point out - storing integers in varchars is definitely a bad idea!)

SELECT orderId FROM orders where orderRef='737357947879';

was almost instantaneous

MySQL was doing a full table scan casting orderRef to an integer at each step then matching with the integer I was passing in.

Just finished stuff2send.com

Just finished development of www.stuff2send.com for Colin Hay, Everything was produced in double quick time in order to get it working in time for Christmas. Jolly hard work also there is not always time to properly consider what you're doing when you have to write code so quickly, this results in a longer testing phase. Fortunately Colin is an excellent software tester and feedback was excellent. Learned jQuery in the process really excellent.

How to get flash working on Ubuntu

Have just got Ubuntu working on my gorgeous hp 2133, but flash totally refused to play on opera and firefox. Eventually I discovered that running ldd on the flash shared library /usr/lib/opera/plugins showed several dependencies not found:

ldd /usr/lib/opera/plugins/libflashplayer.so | grep not
libssl3.so => not found
libplds4.so => not found
libplc4.so => not found
libnspr4.so => not found
These libraries are there in /usr/lib but have slightly different names. Symbolically linking the ones that flash requires fixes the problem!

e.g. cd /usr/lib

What I'm Up To

Currently:-

Working on the design for 2 new CakePHP sites. missionaryboard for churches to get a google map on their site showing where their missionaries are. The other will have to remain a secret for now.

Putting the finishing touches to backupchute web site backup service.

Building USB/MP3 duplicators.

Building Drupal Modules.

Learning lots & lots. Thank goodness for my Safari account!

How to tell if you are a man or a woman

An alien from a distant and far superior race comes to earth. He finds the place enchanting, so before leaving he gives you a gift for the whole human race. The gift is a small sphere that has the power to end all world conflict.

Do you

[A. Woman] Give it to the Secretary General of the United Nations.
[B. Man] Take it apart to try to figure out how it works.

Syndicate content