by Karl Bunyan

Programming, PHP, JavaScript, .Net, motorbikes, pubs, poker, football, news, restaurants and anything else


MySQL Truncate slow performance problems

I was having problems with a MySQL TRUNCATE taking a long time on a very large table (with foreign keys). I had thought that TRUNCATE ran more quickly than DELETE but, according to the MySQL manual, that isn't the case with InnoDB tables. In this case there is no difference between TRUNCATE and DELETE and it's recommended to drop the table and then re-create it. That sounds like a very high risk operation to me, but given that the TRUNCATE statement is taking an hour and a half to run then it looks like I've got some code to write. TRUNCATE in the MySQL documentation

Link to this post


My solution to this can be found here.
posted by Blogger Karl Bunyan : August 18, 2005 11:47 AM  

Post a Comment

Restaurant review: Vic Naylor's, Clerkenwell, London

Vic Naylor's in Clerkenwell is one of a collection of reasonably up-market restaurants along St John Street. On entering the bar/restaurant one is struck by the effort that has been put into the interior, yet somehow it appears very natural. It's also slightly more distinctive than the formulaic modern interiors that seem to be the default nowadays.

We arrived half hour early and sat for a drink at the bar. There's a relaxed feel to the place and a slow trickle of people coming in through the door filling up the restaurant. Once our drinks were finished it took nothing more than hopping off our stools and a glance at the waitress for her to show us straight to our table. This was certainly impressive attention to customers, especially given that there only seemed to be two waiting staff for the 30 or 40 seats in the restaurant.

Service throughout was also excellent. We weren't hurried at any point, if we asked for a couple of minutes to decide on something then we would be left alone and, importantly, someone would come back to see to us a few minutes later. There were no large gaps between courses (unless we felt we needed the rest) and despite time being shared between the two staff they obviously kept in touch with who had ordered what dish so there was no need to ask as they brought food to the table.

The food was very good too. Throughout the three courses on the menu there is a variation from the more conservative to more adventurous modern european food, including (on the night we visited) steak, duck breast and risotto, and prawn and crab ravioli. Each course was well presented and richly flavoured yet somehow had a lightness of touch as the different tastes balanced each other.

The only possible downside was I felt that the winelist was slightly on the expensive side (ranging from around £12 upwards), although that seems to be par for the course nowadays. The wine itself (a Rioja Blanco) was good, however, so there has obviously been some thought put into the selection. Price-wise we came in at just over £40 a head, including a decent tip, which for three courses, wine, water and coffee seemed fair. In fact, given the prices of some London restaurants it's very good value for money.

Clerkenwell has certainly changed over the past few years. When I first worked there back in 1998 you certainly wouldn't think of going there on a Saturday evening on the off-chance of a good restaurant being open. Clerkenwell has been transformed into a trendy night-spot (albeit a slightly exclusive one) and, along with most of the other good restaurants in the area, booking is advised for Vic Naylor's.

Address: 38-40 St John Street, London, EC1M 4AY
Nearest tube: Farringdon

Other reviews:
Vic Naylor's on London Eating
Vic Naylor's on London Eats

Link to this post


I found this useful resource on restaurants and takeaways in South London - http://www.lacartes.com, it features over 1000 restaurants and takeaways each with menus and photos. You can search by distance, price and cuisines which makes it very easy to compare dishes and prices. Very easy to use.
posted by Anonymous dawson : April 17, 2007 3:22 PM  

Post a Comment

Fantasy football league team

We're at second in an office Telegraph's fantasy football league at the moment, which is pretty good, but one of the directors is in the lead and apparently has won for the past two years. Our fantasy football team consists of:

  • Goalkeeper:
    • J Lehmann (Arsenal)
  • Defenders:
    • W Bridge (Chelsea)
    • A Cole (Arsenal)
    • J Carragher (Liverpool)
    • F Queudrue (Middlesborough)
  • Midfield:
    • F Lampard (Chelsea)
    • F Ljungberg (Arsenal)
    • C Ronaldo (Manchester United)
  • Strikers:
    • N Anelka (Manchester City)
    • J Beattie (Southampton)
    • JF Hasselbaink (Middlesborough)

Now the team is doing fairly well, and our defence and midfield are doing very well, but we're still having trouble with consistent goalscorers. Beattie started the season well but Southampton don't seem to be on the move (expect downwards) so I'm in two minds about him. Both Anelka and Hasselbaink have had spurts of scoring well, but we're still not getting the striking points we need. Suggestions welcome...

Telegraph Fantasy Football

Link to this post


If you are interested there's lots of info about fantasy football here

posted by Anonymous Anonymous : April 04, 2005 8:46 AM  

Post a Comment

Review of Yamaha Fazer FZ6 600

Having not ridden a motorbike for some 7 years I sat astride the Yamaha Fazer 600 with some trepidation. I had chosen the bike as it looked like it would have a reasonable amount of power to 'break me in' to the world of bigger bikes, but with a less racey style than the CBR's or an R6. After the owner of the hire shop telling me that 'this is a fast bike' I was already worried.

In terms of speed, I certainly wasn't disappointed. I took it fairly easy on the throttle to start with but after half hour or so of riding I felt like the full range of power was easily controllable.

Out on the open road the Fazer does have pretty good acceleration. I know it's not up there with a CBR 600 or an R6 but compared to most other traffic on the road it's more than lively enough. The power band is not as even as I would have liked, though, with a big kick at higher revs. Perhaps if I gave it another go it wouldn't seem so bad but it was something I had to watch out for for a while.

The riding position is reasonably upright. Although this makes it fairly comfortable as a sitting position, the faring is quite minimal and the amount of wind certainly gives you some neck strain after an hour or two. I'd say the almost complete lack of protection the faring gives is the lowest point of this bike overall.

The pillion passenger was pretty comfortable, though: enough so to fall asleep going along the motorway! The other great thing about this bike is it's fuel range: I got more than 175 miles out with two people and luggage, and the fuel tank tells you exactly where you are. This is certainly worth considering with a bike: a CBR 600 needs a fill up about every 120 miles in the same conditions.

All in all, it was a pretty good bike but perhaps a bit too much between stools for me. The riding position wasn't racey and neither is the throttle, but the narrower power bands and lack of faring also don't push it anywhere near the touring bracket. Where this bike would be ideal is as a commuter, with it's good tank range, comfortable riding position and some good bursts of power for overtaking.

I did like the Fazer, and I think one day I'll have another go (the R6 just looks a bit too raw) but I think the real crux is that it's a class of bike that isn't quite for me.

The Fazer FZ6 on the Yamaha site

Link to this post


I would in the main agree, I too have returned to biking after a 10 year break. For touring an aftermarket double double would may be do the trick. the bike is certainly in my opinion capable of touring
posted by Anonymous Anonymous : July 16, 2006 10:16 PM  

Post a Comment

Restaurant and pub review: The Duke of York, Clerkenwell

"The Duke" in Clerkenwell is hidden away down a back street (Roger Street) just off Theobalds Road and Grays Inn Road, London. Although the pub comes across as a 'local boozer', it's clear from the thought that's been put into the decor that it's not intended for a purely local audience. The beer selection is pretty good (a nice selection of ales) and the wine-list is not too expensive, if still a tad on the pricey side.

The pub itself is split into two parts: the bar, and the restaurant. Both are nicely fitted out in a kind of modern-rustic way and it manages to pull this all off without appearing to try too hard.

Our experience went downhill as soon as we asked if we could sit in the (almost completely empty) restaurant half: "As long as you're going to eat.". We said we were waiting for friends, and they agreed to give us a whole 40 minutes before we had to order. 10 minutes later, we were asked again if we were ready to order and had to remind them that we were waiting for more people. The friends arrived, but then we had to run the gauntlet of trying to attract a waiters attention; it was puzzling that after so much harrassment earlier we were actually finding it difficult.

The food was very good when it arrived, although hardly service with a smile. Again, attracting someone's attention for another bottle of wine was an ordeal. The meal/drinks came to around £25 a head in the end, which I don't see is a sum to be sniffed at by a pub/restaurant on a Thursday evening, and although The Duke of York has a very good quality food and a well thought out eating area, the feeling that we were imposing on the staff left us with no desire to return again.

The Duke's website: http://www.dukepub.co.uk
Another review: The Duke review on London Eating

Link to this post


today i found two nice things first a nice blog here and another a nice restaurant in london, of delicious cuisine where you can found out indian, chinense, manchurian, french, italian takeaways at http://www.lacartes.com/
posted by Anonymous Anonymous : March 02, 2007 5:50 PM  

Post a Comment

Honda VFR 800 review

I've ridden a few bikes over the past couple of years including a Yamaha Fazer 600, a Honda CB 500 and a CBR 600 (a few times now). I was really looking forward to trying out the VFR as I thought it would offer a similar ride to the CBR 600 but with some extra power for a pillion passenger.

First impression was odd: the engine chugs away like a car that's on the verge of misfiring, but open up the throttle from virtually any revs and away it goes! The linked brakes took no time at all to get used to: pull the brake, the bike stops. Easy.

On the open road the VFR is a very comfortable and very easy ride. The problem for me was it was a bit too easy to ride. The power band is fairly constant, although when all cylinders kick in above 7000rpm there is noticably more pull, but somehow, for me, that takes the fun out of riding a bike. I prefer the ride of the CBR 600 that will pull reasonably well at low-ish revs but really lets rip further up the band.

My other gripe with the VFR is the size and weight. It handles well once you're up to speed but I never felt as confident in the front tyre as I have on other bikes. I think this may have something to do with the slightly more upright riding position and being seated slightly further back than on a CBR. Or it could just be me. I do know that I managed to lock up a front wheel when a pheasant ran out into the middle of the road and that's never happened to me on any other bike.

In terms of the 'technical' aspects: torque was very impressive, speed was okay, but again I wasn't impressed by the mileage. My main (possibly only) problem with the CBR 600 is the size of the tank, but I could only get a few more miles out of the VFR and it didn't seem to provide any extra speed considering the petrol consumption.

From a pillion's point of view (I was told) it doesn't feel as solid. Again, I think that may be a combination of height and riding position, but pulling down a straight left my passenger feeling like they were going to tip off the back of the bike. This has never happened on a CBR 600 before and I've certainly never held back. Perhaps speed is all about perception and I've never managed to pull away as quickly on a CBR with a passenger before; the VFR certainly didn't seem to notice the extra weight in the same way.

All in all: Honda's VFR 800 is a good bike, but I don't think it's for me. I think my main problems are the size of the bike and slightly more upright riding position. Although the through-the-range power was good, I prefer something that you have to push a bit harder but rewards the effort with responsiveness and a nimble road poise.

Link to this post


Hey Karl,

I like your reviews on motorbikes, but can you please say of what year the bike is? That is ipmortant for a review so readers know exactly what bike you are talking about.

And keep up the good work ;)
posted by Blogger Stefaan : August 14, 2007 8:23 AM  

That's a good point. To be honest: I'm not sure what year the bike was manufactured in but I rode it in 2004 and it was new - which I guess makes it the 2002 6th generation model. It was the one without antilock brakes.
posted by Blogger Karl Bunyan : August 14, 2007 8:29 AM  

Post a Comment

Implementing Iterator in PHP 5

There's a good article on sharepoint about implementing Iterator in PHP 5: http://www.sitepoint.com/article/php5-standard-library/1. I've used it a couple of times now and it's a great way to treat objects as collections.

More info about the Standard PHP Library can be found here: Standard PHP Library with a link to download a windows chm help file for reference.

Link to this post

Post a Comment

MySQL load data infile and foreign key constraints

I've been up against a(nother) MySQL 4/PHP 5 'not doing all I want it to' type problem. This time, it involved trying to do a bulk update on potentially tens of thousands of lines. Now, I don't want to do an INSERT for each line and I've already written some classes to handle outputting data objects into csv files which handles all of the primary keys. There's an option with LOAD DATA INFILE to REPLACE values where primary key conflicts would occur so I thought if I used that with existing rows then I should be okay.

What I have found, though, is that LOAD DATA INFILE with REPLACE appears to try to delete the row and then re-insert it. This breaks other foreign constraints and so the database engine won't let it. Fair enough, but it would have been nice if the manual mentioned it.

So: next step is to disable the foreign keys temporarily with SET FOREIGN_KEY_CHECKS=0. From the command line this works fine, but it seems that within PHP the foreign key checks are re-enabled automatically after each command is run, which means the net result of running SET FOREIGN_KEY_CHECKS=0 is absolutely nothing. So when I try and to the LOAD DATA INFILE the constraints are still there and it doesn't work.

If we trusted MySQL 5 fully yet (and wanted to go through the pain of installing it) I could probably write a stored procedure, with whatever headaches that would bring, but as it is I'm stuck with MySQL 4 for the moment. The solution I've come up with is to write the SQL query to a text file and then use an exec() command from within PHP to execute the commands in the file. I don't like it, and it doesn't feel very portable, but it seems to work. In fact, it seems so handy that I've created a static method so I can do it with any batch of SQL queries.

The handy class follows (with constants in place of the database names/connection values/temporary folder):

public static function multipleDbQueries($sql)
 $file = fopen(TEMP_CSV_LOCATION .
 exec("mysql -u " . DB_USERNAME .
  " --password=='" . DB_PASSWORD .
  "' " . DB_NAME . " < "
  . TEMP_CSV_LOCATION . "temp_query.sql");

Link to this post


Tim in T.O. -
Your solution is helpful; however, I put it in my code and then realized there's a big disconnect between using a DSN as best-practice in my application and then somehow providing username/password for this. Argh! Mysql doesn't know anything about DSNs. So I'll have to hard-code in a new password for the DB, all so I can do a runtime REPLACE which, as you observed, can't handle a foreign key reference.
posted by Anonymous Anonymous : December 20, 2004 4:05 PM  

Post a Comment

Motorbike hire in east London

I usually hire motorbikes from a place called Raceways in Surrey Quays, East London but a) it's quite expensive, and b) they're the wrong side of the river. I'm going to be on a Honda VFR800 this weekend

I'd definitely be interested in finding something a bit closer, though, but East London doesn't seem particularly well served by motorbike hire.

Link to this post


Riverside Motor bike hire Unit 12 Dyehouse Lane, Bow E3 0208 5510221 does cheap and very good quality bike hire
posted by Anonymous Anonymous : January 29, 2005 5:33 PM  

the number above is not correct, but the following links provide alternative contacts for motorbike hire in London and beyond.

I know of these rental places:

In London:




In Wales:


In Barcelona:

posted by Anonymous Anonymous : July 04, 2006 1:29 PM  

I rent motorcycles in France - any of the following web addresses may be useful -
www.motopyrenees.com - ride ideas.

Si on est Francophone:
vous aider

Kind Regards Bill Shw
posted by Blogger Bill : April 01, 2007 4:02 PM  

Post a Comment

Hiring an ASP.Net developer

My company is looking for an ASP.Net developer, so here seems as good a place as any to put an ad. Job description below:

London based Internet development company seeks permanent ASP.NET developer with an absolute minimum of 1.5 years production experience.

Desktop application programming and web services experience are a must as is extensive VB.NET and SQL Server 2000 knowledge. 'Can-do' attitude, a problem ownership mindset, excellent common sense and the ability to communicate clearly to internal and external clients are also pre-requisites.

Exposure to SOAP and programming languages such as C#, XSL and PHP would be a distinct advantage.

This is an excellent opportunity to join an ambitious, young and profitable business at the beginning of an exciting growth phase.

No agencies.

Email: asp dot net at exponetic.com

Link to this post

Post a Comment

PHP 5 garbage collection

The object-oriented features of PHP 5 are a really positive step forward for the language. One of the biggest improvements, to my mind, is that you no longer have to choose to pass things around by reference with a liberal smattering of '&' symbols: references are now the default way of passing objects. One problem I have come across, though, is that the reference counting feature of PHP's garbage collection (http://www.zend.com/zend/art/ref-count.php) means that objects with mutual references are not deleted even when I thought the object was out of existence. E.g:

class ParentObject()
  protected $childObject;

  function __construct()
    $this->childObject = new ChildObject($this);

class ChildObject()
  protected $parentObject;

  //Pass in a reference to the parent
  //object and store it internally
  function __construct($parentObject)
    $this->parentObject = $parentObject;

Then if I call $foo = new ParentObject(); then it automatically creates a child object with a reference to the parent. The parent also keeps a reference to its child. If I then unset($foo); the two objects are still referencing each other and so are not deleted. The only way I've found to clear this is to create a new method (which I call destroy()) to delete references to the child. Calling destroy() on the parent first calls destroy() on its child, which dereferences the parent, and then the parent dereferences the child. So the classes are now:

class ParentObject()
  protected $childObject;

  function __construct()
    $this->childObject = new ChildObject($this);

  public function destroy()

class ChildObject()
  protected $parentObject;

  //Pass in a reference to the parent object
  //and store it internally
  function __construct($parentObject)
    $this->parentObject = $parentObject;

  public function destroy()

And I have to call


To clear the thing out completely. This can cause a number of problems which I won't go into in detail here (they occur in more complex design patterns), but suffice to say that there are a number of occassions where I don't necessarily want to destroy a child at the same time as a parent, or vice-versa. E.g. a child references multiple parents. The end result is that I'm writing code to deal with garbage collection where it is having a big effect on memory and just leaving it out where it doesn't seem to make as much difference. This suffices for a known set of data but doesn't feel very satisfactory in terms of future-proofing. I would appreciate it if anyone else has a better way of doing things.

Link to this post


Why not using the destructor "__destruct()" to clean up?
posted by Anonymous Anonymous : September 22, 2004 9:39 PM  

I take your point and had considered it but (and I haven't actually tried this) I wasn't sure if I called __destruct deliberately then it would be called again when the object was actually destroyed.

The main reason I initially made my own method, though, was so that I could put some code in __destruct to flag that the object had actually been destroyed - some objects were destroying themselves fine, others weren't and __destruct seemed the best way to debug when an object actually disappeared.
posted by Blogger Karl Bunyan : September 23, 2004 9:30 AM  

The destructor isn't called until the object is being destroyed. Because of the existing references, the object isn't being destroyed until the end of the request and therefore putting this code in the destructor doesn't work.
posted by Anonymous Anonymous : July 15, 2005 2:14 PM  

Wow, someone else actually trying to memory manage parent-child relationships in PHP!

So, I have been grappling with this problem while working on Propel. I actually found a way to create non-refcounted references in PHP5... if you $a = &$b; where $b is an object, $a points to it, but doesn't bump the refcount. Which is half of the solution...

The other problem I've found though is that you can't create a non-refcounted reference to $this, so in your function like $child->setParent($this) it doesn't work. It does work if you $child->setParent($parent) though, and then you don't have to explicitly call destroy() methods.

I am trying to find a way around the $this problem as we speak....

posted by Anonymous Alan Pinstein : December 06, 2005 9:39 PM  

In reply to alan, apparent you can use $this->this to get a non ref-counted reference to a class. I have this recursive reference problem, and thats one way around it, althou there is a severe lack of documentation about $this->this


Only thing is i have no idea what version of php5 these guys are using, 5.1.2 that i'm using seems to be missing this functionality.
posted by Anonymous Chris Seufert : April 12, 2006 11:06 PM  

Post a Comment

Sony Clie and Nokia 6600 infra red GPRS internet settings

Instructions for connecting the Sony Clie UX50 to the internet via GPRS through a Nokia 6600's infra red port. I'm on the Orange phone network so some of the settings may be specific to this. I also assume your phone already works with internet/GPRS by itself and has a connection called 'orangeinternet' set up (which it is by default).

  1. Go to Preferences.
  2. Select 'Connections' and 'New..'.
  3. Call it something like 'IR Internet'.
  4. Set:
    • Connect to: Modem
    • Via: Infrared
    • Dialing: TouchTone
    • Volume: Low
  5. Click on 'Details' and set speed: 115,200, flow ctl: Automatic, Init string: leave empty.
  6. Click 'OK' then 'OK' from the 'Edit Connection' screen.
  7. Select 'Network' from within Preferences.
  8. Open up the top menu and select 'New'.
  9. Call the service something memorable (e.g 'Working IR Internet').
  10. Some of the following settings are specific to the Orange phone network so you may have to play around:
    • Username: a
    • Password: a
    • Connection: select the IR connection you just made ('IR Internet')
    • Phone: *99#
  11. Click on 'details'.
  12. Set:
    • Connection type: PPP
    • Idle timeout: Never
    • Query DNS: ticked
    • IP Address: tick automatic

Now the hard bit... Click on 'Script' and enter through the menus:

Send: AT&FO&D2&EO [both capital "o", not zeros]
Send CR:
Send: ATV1W1S95=47
Send CR:
Send: AT&K3
Send CR:
Send: AT+CGDCONT=1,"IP","orangeinternet"
Send CR:
Send: ATDT*99#
Send CR:

Click on 'OK'.

Now to try and connect the phone to the Clie. Go to 'Modem' option in the Nokia 6600's menu (probably inside the 'Connect' folder if you haven't moved it). Click on the 'Modem' icon and select 'Connect via infrared'. The phone should start looking for something to connect to. Now go to the network setting you've just made in the Clie, point the infra red port at the phone's IR port and click 'Connect'. Then hope for the best....

This obviously isn't as good as bluetooth would be because a) you have to point the devices at each other and b) you have to navigate through a few menus just to enable the modem on the 6600, but it's the best we seem to have for a while.

Link to this post


Hi, dude. Have you already connected trought a nokia 6585i ir connection using a clie peg nx80v?
posted by Anonymous Anonymous : June 11, 2005 1:45 AM  

posted by Blogger Karl Bunyan : June 17, 2005 1:33 PM  

Post a Comment

the5k.org web page competition

The 5k web page competition looks like it might finally be getting going again. News about it is here: Siggraph's 5k competition.

However, I'm somewhat confused as the closing date in the right hand side column is set at July 14th 2004, yet the application form has July 14th 2005. Does anyone have any ideas what's going on?

Link to this post

Post a Comment

Sony Clie and Nokia 6600 bluetooth gprs internet access

I've been spending quite a lot of time trying to get internet access from my Sony Clie through a Nokia 6600 mobile phone's bluetooth connection and have had some minor success but still not been able to get it to work completely. A major break through came with getting infra-red access (taking a step back seemed like the best way to start out) but Bluetooth/Nokia 6600/Sony Clie just don't seem to like each other very much.

There are rumours about an upgrade to the 6600's firmware which may improve things, but it doesn't seem particularly easy to get hold of at the moment: either send your phone away for god knows how many weeks, or try and grab a dodgy copy and do it yourself invalidating the warranty. I think i'll wait until there's positive news on it actually fixing the problem first.

The stage I've now gotten to is:

  1. Can connect to the internet, e-mail and ssh fine via infra-red.
  2. The Nokia 6600 and Clie are paired via Bluetooth.
  3. Sending files back anf forth between the 6600 and the Clie works fine.
  4. Sending SMS messages from the Clie via Bluetooth works fine.
  5. Can make a connection to the internet via Bluetooth but unable to sustain it for any download. The strangest thing is that I can send e-mails.

A great source for the Palm dial-up script and settings for connecting to Orange can be found here:
Orange/Palm GPRS script
A Palm OS Nokia 6600 phone driver can be downloaded here: http://www.clieuk.co.uk/upload/Nokia6600.prc

There's an interesting thread on the matter here: Clie/Nokia 6600 GPRS internet discussion.

Link to this post

Post a Comment

At last I've gotten round to writing something!

Having signed up for blogger back in september 2003 it's now taken me just over a year to get round to writing a first proper post. A short intro: I'm a director of a web development company called Exponetic based in Bethnal Green, London.

If you haven't been to Bethnal Green: it's a marvellous place. Where else could you buy something like this?:

Bethnal Green curiosity

Link to this post


dear karl
yes i agree bethnal green is a colourfull & historical place evan to this day even though i dont live there anymore it still hold true in me the eastender evan after 33 years i still remember bethnal green rd brick lane victoria park fishing in canals ? pie&mash baigals in brick lne and every where i went as a boy & even after revisting relatives later who still live there.best wishes stephen
posted by Anonymous stephen : July 30, 2005 1:24 AM  

Post a Comment


Current Posts

Other links

Change the background image