NavigationUser login |
Profiling PHPI'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 factorySuppose 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.
Why PHP code can sometimes be so bad ...
PHP Bad Practice
jQuery saves baconJust 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-patternI 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 learntRunning the following query: SELECT orderId FROM orders where orderRef=737357947879; Was taking 2 seconds, despite the key on orders.orderRef 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.comJust 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 UbuntuHave 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 e.g. cd /usr/lib What I'm Up ToCurrently:- 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 womanAn 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.
|
Recent blog posts |