about:benjie

Random learnings and other thoughts from an unashamed geek

Blog Friends Update

| Comments

Sorry I haven’t written a post for ages! I thought I had better keep you up to date with Blog Friends - we have (finally!) released version 1 beta ( Blog Friends v1 Beta), which is (according to subversion) revision 816 of Blog Friends! We have had a lot of positive feedback on the new release, but also a lot of confusion over the new features and the perceived “lack of control” (you can find lots of the options, such as how many posts to put in each section of your profile box, on the settings page). After reading all of the comments from our users we found that a common complaint was that of finding “strangers” in their Facebook profile boxes. We quickly made some simple changes to get these strangers out, and are currently working on doing a much improved profile box, incorporating a lot of the ideas we have gained from users feedback. You can see a preview of this new profile box here, and we would appreciate your comments on it - we read every piece of Blog Friends feedback we can get our hands on!

On a finishing note, you can read a great post by Allan Cockerill on Blog Friends and the Blog Friends Blog here. It is worth noting that we intend to use the Blog Friends Blog as a place to keep our users updated with changes, and also a place for feedback, so if you have opinions on the posts there, please tell us through the comments! (Even if someone has already said what you were going to say, there is no harm reiterating it!)

PHP Preg_replace Segfault Fixed

| Comments

So I finally fixed the issue here, by replacing

Segfaults
1
2
<?php // For syntax highlighting
$data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i', '', $data);

with

Doesn’t segfault
1
2
<?php // For syntax highlighting
$data = preg_replace('/ '. trim($attrib) .'=[\w\s=:;\/.?&,#!()\+{}-]*/i', '', $data);

Back to work I go.

PHP Segfault-ing: Preg_replace

| Comments

Update: issue now fixed.


ARGH! I cannot yet figure this one out. This code segfaults (gives memory allocation errors to) my copy of PHP, and also that on simplepie.org, but not that at php5.simplepie.org (the dev server). So there must be a difference in the PHP compilation/dependencies (as I am told that the versions of PHP are the same).

And yes, the &amp;amp; stuff is deliberate.

This is really frustrating. Ideas, anyone?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
$attrib = "id";
$data = <<<END
&amp;amp;amp;amp;amp;nbsp; width=&amp;amp;amp;amp;amp;quot;340&amp;amp;amp;amp;amp;quot; height=&amp;amp;amp;amp;amp;quot;289&amp;amp;amp;amp;amp;quot; id=&amp;amp;amp;amp;amp;quot;player&amp;amp;amp;amp;amp;quot; align=&amp;amp;amp;amp;amp;quot;middle&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;lt;param name=&amp;amp;amp;amp;amp;quot;movie&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;http://cdn.last.fm/videoplayer/21/VideoPlayer.swf&amp;amp;amp;amp;amp;quot; /&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;lt;param name=&amp;amp;amp;amp;amp;quot;menu&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;false&amp;amp;amp;amp;amp;quot; /&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;lt;param name=&amp;amp;amp;amp;amp;quot;quality&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;high&amp;amp;amp;amp;amp;quot; /&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;lt;param name=&amp;amp;amp;amp;amp;quot;bgcolor&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;#000000&amp;amp;amp;amp;amp;quot; /&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;lt;param name=&amp;amp;amp;amp;amp;quot;allowFullScreen&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;true&amp;amp;amp;amp;amp;quot; /&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;lt;param name=&amp;amp;amp;amp;amp;quot;flashvars&amp;amp;amp;amp;amp;quot; value=&amp;amp;amp;amp;amp;quot;creator=The+Chemical+Brothers&amp;amp;amp;amp;amp;amp;title=Do+It+Again&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;uniqueName=Do+It+Again&amp;amp;amp;amp;amp;amp;albumArt=http://cdn.last.fm/coverart/130×130/3341430-870824884.jpg&amp;amp;amp;amp;amp;amp;album=We+Are+The+Night&amp;amp;amp;amp;amp;amp;duration=278&amp;amp;amp;amp;amp;amp;image=http://panther3.last.fm/storable/videocap/7808/0/original.jpg&amp;amp;amp;amp;amp;amp;FSSupport=true&amp;amp;amp;amp;amp;quot; /&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;lt;embed src=&amp;amp;amp;amp;amp;quot;http://cdn.last.fm/videoplayer/21/VideoPlayer.swf&amp;amp;amp;amp;amp;quot;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; menu=&amp;amp;amp;amp;amp;quot;false&amp;amp;amp;amp;amp;quot; 
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; quality=&amp;amp;amp;amp;amp;quot;high&amp;amp;amp;amp;amp;quot; 
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; bgcolor=&amp;amp;amp;amp;amp;quot;#000000&amp;amp;amp;amp;amp;quot; 
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; width=&amp;amp;amp;amp;amp;quot;340&amp;amp;amp;amp;amp;quot; height=&amp;amp;amp;amp;amp;quot;289&amp;amp;amp;amp;amp;quot; 
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; name=&amp;amp;amp;amp;amp;quot;player&amp;amp;amp;amp;amp;quot; 
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; align=&amp;amp;amp;amp;amp;quot;middle&amp;amp;amp;amp;amp;quot; 
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; allowFullScreen=&amp;amp;amp;amp;amp;quot;true&amp;amp;amp;amp;amp;quot;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; flashvars=&amp;amp;amp;amp;amp;quot;creator=The+Chemical+Brothers&amp;amp;amp;amp;amp;amp;title=Do+It+Again&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;uniqueName=Do+It+Again&amp;amp;amp;amp;amp;amp;albumArt=http://cdn.last.fm/coverart/130×130/3341430-870824884.jpg&amp;amp;amp;amp;amp;amp;album=We+Are+The+Night&amp;amp;amp;amp;amp;amp;duration=278&amp;amp;amp;amp;amp;amp;image=http://panther3.last.fm/storable/videocap/7808/0/original.jpg&amp;amp;amp;amp;amp;amp;FSSupport=true&amp;amp;amp;amp;amp;quot;
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; type=&amp;amp;amp;amp;amp;quot;application/x-shockwave-flash&amp;amp;amp;amp;amp;quot; 
&amp;amp;amp;amp;amp;nbsp; &amp;amp;amp;amp;amp;nbsp; pluginspage=&amp;amp;amp;amp;amp;quot;http://www.macromedia.com/go/getflashplayer&amp;amp;amp;amp;amp;quot; /&amp;amp;amp;amp;amp;gt;
&amp;amp;amp;amp;amp;lt;/object&amp;amp;amp;amp;amp;gt;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;

END;

$data = preg_replace(/ . trim($attrib) .=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i’, ”, $data);

echo "No segfault here";

MySQL Limitations - Triggers and Subqueries - and Solution!

| Comments

A comment on my blog just prompted me to write a new post that hopefully helps someone out.

I have just started using triggers to improve the performance of Blog Friends. It appears that MySQL’s support of triggers is rather annoying…

One fault it has is that it will not let you update a table that the trigger was called from - you get the following error:

“#1442 - Can’t update table ‘users_users’ in stored function/trigger because it is already used by statement which invoked this stored function/trigger. ”

Now, as it happens, I was not actually updating that table, I was updating a different table, just using that as a JOIN:

UPDATE othertable JOIN users_users ON (conditions) SET othertable.value = value+27 WHERE conditions;

See - no writing to users_users at all! But still mysql blocked it.

Now, I thought, no problem, I will re-write it as a subquery:

UPDATE othertable SET value=value+27 WHERE id IN (SELECT id FROM users_users WHERE conditions) AND moreconditions;

But MySQL detects this as a DEPENDENT SUBQUERY even though it was not (my one wasn’t, at least… it only referenced NEW.values and not anything from othertable). It seems MySQL has many issues with SUBQUERYs. Well; it worked, but OMG was it slow?!! I almost had time to go and make lunch before it finished just working on 10 users… This was not good.

After a lot of moaning and no answers on #mysql on irc.freenode.net (which is unusual - normally there is people in there who know the answers to my questions!) a thought suddenly struck me…

INSERT INTO othertable(id,value) SELECT id, 27 FROM users_users WHERE conditions ON DUPLICATE KEY > UPDATE value=value+27;

Now in my application, the row should already exist, so there is no problem (and even if it didn’t the INSERT would do no harm), but if you intend to use it I suggest that you ensure that this INSERT INTO does no damage.

I hope this helps you! If it does, please leave a comment, and I will put more help!

Summer Camp Log

| Comments

First of all a note to say, I am sorry I took so long to publish this - have been very busy. Wrote it a couple of weeks ago and then forgot about it - and putting all the image thumbnails in takes a while, even if you can script it through image magic… ;-)

The last summer camp I went on was 2 years ago as last year I was too busy with Brain Bakery to allow myself time off to go camping. I learned from last summer that that was a foolish decision and that because I work so hard I need a fair amount of time off to recover – my brain was absolutely mush by September last year!

Since my last summer camp, 3rd^ Ringwood Scout Troop has acquired a new Scout Leader (SL), Mike, who includes amateur radio, whittling and knotting amongst the interests and skills he brings to the Troop. The previous leader, my Dad, Dave (Skip) now holds the position of Group Scout Leader (GSL). Inevitably, with a change of leadership often comes a change in programme content, and sure enough the camp’s focus leaned more towards visiting local attractions than previous camps had (and thus spent less time on-site). This is not really a bad thing – the Scouts seemed to really enjoy their time off-site, but personally I regret that the Scouts missed the opportunity to cook on open fires at least once – they either cooked on gas or had their dinner made for them most of the time.

This difference in focus is probably partly a result of the change in age ranges that the Scout movement implemented a few years ago – something that I do not agree with as it means that just when the Scouts start showing some real leadership skills, and start to use the knowledge that they have spent the last few years acquiring, they have to move on to the next age section (Explorers). Scouting used to work quite well with 15 year old patrol leaders as the rest of the patrol respected them, and they knew quite a bit of what they were doing. Unfortunately with 13 year olds they do not have that implicit respect, nor the knowledge required, so are unable to properly lead their patrols. I think it is probably for these reasons (and those of time) that Mike decided that cooking on open fires could not be accommodated on this camp.

We did, however, still spend a fair bit of time on-site and did inspections most days, trying to teach the children (“young adults”) how they should set out their site, how to look after their cooking utensils and equipment, and how to stay safe and warm. Unfortunately we cannot make them do things so a lot of the advice went unheeded due to laziness and lethargy – but I hope that next summer they will remember (or be reminded) and will set their sites up correctly from the very start. It only takes a few more minutes work at the beginning of the camp to increase the comfort and safety of their site considerably.

Anyway onto my brief log:

Saturday

We spent the whole day travelling and setting up camp.

Sunday

Lulworth Cove [Pic:1560, Lulworth Cove] On the second day of camp, once we had completed a full kit inspection (which took almost 3 hours due to the Scout’s laziness!), we headed down to Lulworth Cove for a bit of time on the “beach” and some ice creams. It is a beautiful area with some amazing natural features, such arches and blowholes.

Arches and blowhole [Pic:1565, arches and blowhole]

Monday

Tanks on route [1566, tanks on route] The next day we went for a walk out over the Lulworth Range Walks – this is in the midst of MOD land where they frequently practice with tanks to train the troops. They open the area to the public for a couple of weeks each summer – but warn us to stick to paths as there may be unexploded shells off of them.

This is the view from the carpark at the top of the hill.

Sign with warnings [1570, sign with warnings] View from carpark [Pic:1569,view from carpark] View out over military beach [Pic:1584, view out over miliary beach] View of white cliffs and beach during descent [1589, view of white cliffs and beach during descent] We walked down an extremely steep hill (there was small foot sized steps cut into the hill to aid descent) down to a beach that is normally inaccessible to the public. The descent was so steep that us leaders’ knees were shaking badly by the time we got to the bottom! Good job there was a beach for us to relax on, and have our lunch.

Panorama of beach on which we had lunch [Pic:1592, panorama of beach on which we had lunch] We then walked around an old deserted village which Jem and my Dad found very interesting. I don’t remember being more bored… I am more of a “new” person than an “old” - I like to look to the future rather than the past. I enjoy new technologies, old ones hold little interest to me (unless they are radically different, in which case I can get quite intrigued). Anyway enough about me…

Tuesday

Me, courting an old army gal [1600, me courting an old army gal] Jem with a gun [1603, Jem with a gun] On Tuesday we went to the tank museum – not really my cup of tea, but almost everyone else enjoyed it (man, I am such a misery-guys…) It was on this day that I was ripped off massively by an ice cream van who did not display the prices of the ice creams – they just told you once you had placed your order. I was charged £2 for a broken, tiny, imported. cheap, poorly manufactured strawberry split. Still it did serve to cool me down. Grrr.

Wednesday

This was a very important day for Scouting – it was the 100th^ anniversary of that first ever Scout camp, held by Lord Baden-Powell on Brownsea Island in 1907. I am very proud to be a member of an organisation which now spans over 160 countries, many religions, and brings us all together as a family. It really is quite amazing.

The sun finally rises! [Pic:1643, the sun finally rises!] To celebrate this anniversary, we decided to take part in the “Sunrise Ceremony” (something that did not officially happen until 8am, but we decided to get the Scouts up at 3:30 and walk them up a hill for the actual sunrise at around 5:34am…) where Scouts across the world would renew their promise. Worldwide Scouting has a common theme - “One world, one promise” - something Jem and I would be reminded of many times whilst on the Jamboree a week later.

the cubs and me (green t-shirt, yellow gloves) on “the web” [1681 – the cubs and me (green t-shirt, yellow gloves) on “the web”] Many people joked that I would not be able to survive for a whole week without the internet. As it was, I barely missed it (only a few times when I was phoned up about possible problems with Blog Friends – I had no way of checking the servers myself without the internet). Well, I decided to make a “web” of my own – it was hardly world wide – it could only have a few users at a time (number dependent on weight of individuals!) You can see the fruits of our labour in the picture to the side. I told the cubs “only 3 on it at a time” - there was 12 on it at one time after that… totally ignored me. By the time they got off it almost touched the floor! We had to completely re-rope it.

The act of making things from ropes and poles is called pioneering in Scouting, and I really enjoy it. We also made a swing (our first project) and a “monkey bridge” between a few trees. Normally I use a lot of poles in my pioneering, but there were so many trees available that it was not necessary this time… almost a shame as we had brought more poles with us than usual. I just used an A-frame to tighten the monkey bridge at one end. I also used a couple of windlasses to tighten the hand rails.

Thursday

the red knight losing a lance to the evil black knight from the depths of hell, Lord Odeous... [1718, the red knight losing a lance to the evil black knight from the depths of hell, Lord Odeous…] We went round the corner to Lulworth Castle where we watched the jousting (by “Horses Impossible”) - it was really amazing to watch, though the rain during the first half was a real pain… We were all soaked through, but it was well worth it.

Picture of sheepies, for Jem. [1733, Picture of sheepies, for Jem] Just outside the castle were fields of sheep. The sheep were so noisy at times that we could hear them from our camp site!

Friday

We packed up camp, and set up bivouacs (that is sort of tents made from natural materials found nearby (such as ground sheets…)). Jem and me opted to use our web to sleep on… it would have been great had we not have slipped down to the bottom (it was sloped) where the ropes were less dense – we ended up half hanging through the web! Still, it wasn’t too bad… better than sleeping amongst the ants and woodlice…

Saturday

We took down the remaining pioneering and all the bivouacs and returned back to Ringwood, where we unloaded everything into the stores and then went home.

All in all good camp, enjoyed by all who completed it.

By the way, I have left in my captions and image numbers so that members of the group can request larger copies of the photos from me. Email me on benjie at jemjie dot com.

SimplePie Memory Leak

| Comments

Quote from SimplePie wiki:

When processing a large number of feeds (via a cron job or MySQL loop), a memory leak can occur causing PHP to run out of memory. This is due to PHP Bug > #33595 where PHP doesn’t release memory when making recursive (i.e. self-referential) object calls.

This bug has troubled me for a while with Blog Friends, and caused me to stay with older versions of SimplePie. However, today I think I may have fixed it.

I have put up details of my fix on the SimplePie wiki page linked above, but reproduce them here (without syntax highlighting) for your convenience…

Possibly Solution\ \ The problem is due to recursive references within SimplePie (and PHP’s poor handling of said references). A solution that works for me is patching the vanilla SimplePie 1.0.1 with this:\ \

<code>\ — simplepie1/simplepie.inc (revision 528)\ +++ simplepie1/simplepie.inc (working copy)\ @@ -668,6 +668,12 @@\ $this->init();\ }\ }\ + function __destruct() {\ + if (isset($this->data[‘items’]) && is_array($this->data[‘items’])) foreach (array_keys($this->data[‘items’]) as $k) {\ + $this->data[‘items’][$k]->__destruct();\ + unset($this->data[‘items’][$k]);\ + }\ + }\ \ /**\ * Used for converting object to a string\ @@ -1521,6 +1527,7 @@\ return false;\ }\ }\ + $locate->__destruct();\ $locate = null;\ \ $headers = $file->headers;\ @@ -2703,6 +2710,9 @@\ $this->feed = $feed;\ $this->data = $data;\ }\ + function __destruct() {\ + unset($this->feed);\ + }\ \ function __toString()\ {\ @@ -10013,6 +10023,9 @@\ $this->timeout = $timeout;\ $this->max_checked_feeds = $max_checked_feeds;\ }\ + function __destruct() {\ + unset($this->file);\ + }\ \ function find($type = SIMPLEPIE_LOCATOR_ALL)\ {\ </code>

\ Then all you have to do in your code is ensure that you call $sp->__destruct() once you are done with the SimplePie instance.\ \ If you don’t need multiple concurrent SimplePie classes (i.e. you use SimplePie in a serial fashion) you could use a custom loader to do that… for example:\ \

\ function SimplePie_Loader($url) {\ static $sp = NULL;\ if ($sp !== NULL) { \ $sp->__destruct(); \ $sp = NULL; \ } \ $sp = new SimplePie($url); \ return $sp; \ }\ </code>

\ I hope this helps someone.

Back From Holiday

| Comments

Well, it has been a busy couple of weeks! First I went on summer camp with my Scout Group ( 3rd^ Ringwood) and then I went to the Jamboree for a few days in Essex! It was a fantastic break and I am very glad I did it – gave the old brain some time to refresh!

I finally got back to Southampton on Wednesday afternoon – sorry I have not had chance to post since then, I have been very busy working on Blog Friends which now has over 2,200 users! It is still growing fairly steadily – we have lots of new features in the pipeline which we will be working on over the next couple of weeks and releasing on a rolling schedule.

At the moment I am on the coach writing this – I am going to London to flat-sit my friend and co-worker Luke Razzell’s house! Unfortunately I do not have one of these mobile datacards (they are so expensive!) so I will have to post this when I get in…

conGRADUATIONs

| Comments

Yes, that is right - I have graduated!

I graduated on Monday, but have been sooooooo busy working on the facebook application: Blog Friends that I have not had time to post!

It was a great experience seeing all my friends go up and graduate (and myself of course), though I found it nerve wracking at the start of the ceremony as I had not had time to fully read the graduation website telling me what I should be doing - and to make matters worse, I was seated right at the bottom corner of the students seating area (there was a larger seating area for family & friends) - nearer than any student to the centre of the graduation hall! This made me think that it was likely that I would be first, and I was worried I would do something wrong, what with not having anyone to follow! Fortunately, the people at the very back of the hall were the first to graduate so I did not have to lead whilst knowing nothing of what I was meant to be doing!

The queues to get photos of me in graduation gear were pretty long, but after queuing for 30 minutes or so, we went to the party where there was enough food for everyone to have a whole meal! (I was expecting just nibbles and champagne!) I ate well and enjoyed their desserts whilst talking to my fellow students and some lecturers. It was a good evening. By the time I got home I was exhausted, so just curled up on the sofa with Jem and watched a horror movie :-).

Chapter 3 - Life

I think that graduation marked the end of a chapter of my life - Education. It seems so long ago that I started infant school (in fact I barely remember it at all - just the recurring dream of myself being able to fly like a leaf… but let’s not go into that… [it seemed so real!]) - and it is amazing to think that I have been being educated formally for more than the last three quarters of my life! Thats partly why I thought, upon graduating:

Today, I am an adult

It is worth noting that although I have finished education, I have not finished learning (as many people love to point out, over and over again…). Nope, I will be learning new things every day of my life! That is especially true with my job - where staying up with the forefront of internet technology is extremely important!

Anyway I have lots left to do by this weekend, so I had best get back to work! I will try and start posting more frequently, starting in a couple of weeks or so… Have fun, all!