Macgirvin.COM

   
Apr 27, 2006
Fortune in mySQL
by mike (Mike Macgirvin)

So would anybody be interested in obtaining a mySQL import file containing the complete contents of fortune-mod? If you have need of such a thing, you'll know what to do with it. I whipped this up after finding that the latest fortune-mod package now takes about 7 seconds on a fast machine to produce a cookie. This is totally unacceptable. The reason for this is that some recently added command line switches let you specify the probability that any particular category will be chosen. In order to calculate this number, the program by default loads in all the fortunes from all the category files so it can count them all. 

This collection belongs in a database. Randomly selecting one element from within a collection of elements and then from within a collection of flat files (after counting each entry and then assigning probability weighting to each file) is ludicrous. 

So I looked all over the web for a mySQL table containing the fortune database but couldn't find a single one. Weird. In my travels I found a tool to add fortunes to mySQL but it was pretty badly written. So I started over and did all the dirty work for you. Use these tables as you wish. 

First file is fortune-mod.1.99 in a table named 'fortune' with two elements, 'id' and 'fortune'. 'id' auto-increments.

Second file is the 'offensive' tree in a table named 'fortune2' which is otherwise identical to the first. You can keep them separate, merge them, whatever. 

You can pull out a fortune cookie with the following SQL - just point $table at either fortune or fortune2.  

SELECT `fortune` FROM `$table`ORDER BY RAND() LIMIT 1

To display on the web, you'll need to escape the HTML entities and translate linefeeds (or it will look like mush). I use something like this... where $cookie is the raw fortune from the SQL query:

str_replace(array("&","<",">",'"',"\n"), 
array("&amp;","&lt;","&gt;","&quot;","<br />"),
$cookie);

The third file (fortune-mod.sql.gz) is the complete fortune-mod.1.99 in a single table. This table contains a couple of extra fields. The 'category' field contains the original fortune-mod category name, such as 'quotations' or 'zippy'. There is also an 'offensive' field which is an integer 0 for normal fortunes, 1 for offensive fortunes. Making use of these extra fields is left as an exercise for the reader. One more thing... the third file also has been stripped of all the fortunes containing backspace characters. These might be OK for a text terminal, but they look pretty ugly on the web. 

Enjoy. 

Comments? | More Actions Open/Close menu
Apr 02, 2006
Relative to absolute URL's in PHP
by mike (Mike Macgirvin)

I tried to save myself the normal hassle of creating a regular expression to convert any relative URL's that appear in my RSS feeds to absolute form. Writing regex's is often a painful and time-consuming process. Besides, this is a problem that must've been solved before. Right?

Turns out that it has, but not as often as I would have thought. Buried on page 29 of the search results I finally found a cute little regex that did what I wanted.

Well, not quite. A beautiful function, but hopelessly broken. You see the author (I won't embarrass him by naming him in public) wrote something like '[^http|ftp|https]' to dig out an existing protocol string. Brackets in perl regex's (just like eregs) denote a character range. So this function didn't work if the relative URL began with any of the characters 'h,t,p,f,s, or |'.

So much for trying to save effort. Whenever I do this I end up with a function that is just plain broken. Sigh... You get what you pay for. Anyway, I fixed the function. If this applies to what you're doing, at least it works better than the one I originally found. 

<?php
function reltoabs($text, $base)
{
if (empty($base))
return $text;
// base url needs trailing /
if (substr($base, -1, 1) != "/")
$base .= "/";
// Replace links
$pattern = "/<a([^>]*) href=\"(?!http|ftp|https)([^\"]*)\"/";
$replace = "<a\${1} href=\"" . $base . "\${2}\"";
$text = preg_replace($pattern, $replace, $text);
// Replace images
$pattern = "/<img([^>]*) src=\"(?!http|ftp|https)([^\"]*)\"/";
$replace = "<img\${1} src=\"" . $base . "\${2}\"";
$text = preg_replace($pattern, $replace, $text);
// Done
return $text;
}
?>
 

 

Comments:

May 25, 2006 14:02
vision
Hi here is the modified one to access <link attribute:

function reltoabs($text, $base) { if (empty($base)) return $text; //base url needs trailing / if (substr($base, -1, 1) != "/") $base = $base."/"; //echo $base; // Replace links $pattern = "/<a([^>]*) href=\"(?!http|ftp|https)([^\"]*)\"/"; $replace = "<a\${1} href=\"" . $base . "\${2}\""; $text = preg_replace($pattern, $replace, $text); // Replace images $pattern = "/<img([^>]*) src=\"(?!http|ftp|https)([^\"]*)\"/"; $replace = "<img\${1} src=\"" . $base . "\${2}\""; $text = preg_replace($pattern, $replace, $text);
// Replace link tags $pattern = "/<link([^>]*) href=\"(?!http|ftp|https)([^\"]*)\"/"; $replace = "<link\${1} href=\"" . $base . "\${2}\""; $text = preg_replace($pattern, $replace, $text); $text = str_replace("../", "", $text);
// Done return $text; } it can be xpanded to accept even JS ... :-)

sup
August 31, 2006 05:50
sup
Thanks, dude. This is just what I was looking for. I took what you had and condensed it into a single replace which handles both href and src:
preg_replace("/(href|src)=\"(?!http|ftp|https)([^\"]*)\"/", "$1=\"$base\$2\"", $text);


mike (Mike Macgirvin)
August 31, 2006 07:00
[*TOP MEMBER*] mike

Sup -

I thought about doing that but only wanted to apply the absolute reference to named anchors and images. The attributes 'href' and 'src' are used in other tags (href is used in link tags and src in script tags for example). But now that you've brought it up, a relative URL is a relative URL. It's probably a good thing to convert all of them, no matter what kind of element they might be attached to.


Comments? | More Actions Open/Close menu
Jan 31, 2007
Milkman Baconmonkey?
by mike (Mike Macgirvin)

This went by on jwz's dnalounge blog the other day, but my feed processor doesn't import embedded videos from the wild, so you might have missed it.

Lucky you...

 

Comments:

February 1, 2007 02:02
MichaelAnn
THAT is just odd. Okay, maybe a little creepy, but mostly odd. I'm just sitting here hoping I don't get a tech call before i can let it dissipate from the brain. :)

Comments? | More Actions Open/Close menu
Jan 11, 2007
Numbers
by mike (Mike Macgirvin)

Something isn't adding up. Bush is expected tonight to request an additional 20-30 thousand soldiers for Iraq. And to meet this goal there are going to be more callups of the reserves and extensions of current duty tours - which also seem to be made up in large part by reserve troops.

But if you check the reference sources, the US military is supposed to have about 1.4 million active duty personnel - today. If these competent and trained soldiers aren't available to be put to work on the largest military task at hand, where are they? What are they doing?

I for one question the logic of adding an arbitrary number of troops to a situation that is tenuous at best. But a larger question emerges. If we're adding 20-30 thousand weekend warriors to a staff comprised largely of weekend warriors, why not just put a half million active duty folks over there tomorrow and act like we mean business? That would still leave us close to a million folks to handle any other world crises which might demand attention. Surely we don't have any immediate crises requiring close to a million active duty personnel.

It makes me wonder if we really have 1.4 million active duty soldiers. Maybe we don't.... Which brings up the question - how many do we really have? Given the gyrations the military is going through to keep 150,000 or so in Iraq (our most demanding campaign at the moment), it leads me to believe that the total active force must in fact be somewhat less than 300,000 (50% on standby for immediate national defense); and nobody is talking about this because it might point out how badly the volunteer army has failed and how vulnerable we really are.  

Comments? | More Actions Open/Close menu
Jun 06, 2006
Your daily SDR
by mike (Mike Macgirvin)

bj 

Sex: Bush and friends try once again to define a 'marriage' in constitutional legalese. That means something a little more descriptive than two people who decide to hang out with each other. It also isn't good enough to say it's two people who sleep together. A man and a woman. Hmmm. This is the constitution, and we're still arguing over the right to bear arms because they didn't define a well-regulated militia very well. Ultimately this is going to require precise anatomical descriptions in order for there not to be any loopholes. The only problem is that the constitution is read and studied by school kids. It is going to be a very delicate balancing act. 

Drugs: Troops in Afghanistan are going where the action is. That means to the poppy fields. There's a fresh crop. And the U.S. intends to control the valleys. You won't find this in a public policy statement, but to do this, they need to win the hearts and minds of the opium farmers. And the only way to do this is to become better at opium distribution than the Taliban.

Rock-and-Roll: Bill Wyman is more than just a survivor of 40 some odd years with the Rolling Stones. He's also a photographer, and has just published a book of photos which he took while hanging out in hotel rooms. Speaking of the Stones, it has been confirmed that none other than his satanic majesty Keith Richards will be playing Johnny Depp's (aka Captain Jack Sparrow) father in the next installment of Pirates of the Carribean. I have to hand it to the casting director - I think he's a good fit for the part. The only issue is whether or not he's got any acting talent.

Comments? | More Actions Open/Close menu
Apr 03, 2006
HOWTO: adjusting guitar intonation
by mike (Mike Macgirvin)
Adjusting intonation on a guitar is the act of making your guitar play in tune along the entire length of the fingerboard. This is accomplished by making horizontal adjustments to the guitar bridge. Intonation is affected by (a) the position of the bridge, and (b) the thickness and/or material of the strings.

If you have an acoustic guitar which does not allow horizontal adjustments, the only (economical) way of correcting the intonation is to use different strings.

You will need: a precise electronic tuner. While it is possible to adjust intonation 'by ear' it is not very precise and therefore not recommended.

First, put new strings on your guitar. Oxidated or dirty strings will often not be consistent along their length. This is also why you should change strings with some regularity. We recommend changing strings at least every six months - more often if you play professionally.

Set the guitar on a flat surface and tune the first 'E' string exactly to 'E'. Now press the string down at the 12th fret (the octave mark). Observe the reading on the tuner. If the reading is sharp (higher than 'E'), you will need to move the bridge backward (toward the base of the guitar). If it is flat (lower than 'E') you will need to move the bridge forward (toward the frets). This is accomplished by turning the adjustment screws with either a small flat screwdriver or allen wrench. Adjust it until both the open note and the fretted 12th fret note read exactly the same.

Repeat this procedure for the remaining strings, except you will be tuning to the appropriate note instead of 'E'.

What to do if your bridge does not adjust enough to make the guitar play in tune at the open position and the twelfth fret? There are only two options: (1) physically move the bridge (usually requiring expensive shop work), or (2) use a different string gauge. If the bridge position is at its extreme back setting (toward the base of the guitar) and the twelfth fret reading is still sharp, you will need to use a lighter gauge string. If it is at the extreme forward setting (toward the fingerboard) and the twelfth fret reading is still flat, you will need to use a heavier string. This is also how you would correct the intonation on an acoustic guitar which does not adjust.

You may find that you are forced to use strings which are not comfortable to play. This is understandable; however you must then make some personal decisions. Would you rather have comfort, or would you rather the guitar sound good? Most people would prefer playing a guitar that sounds great, but it is understandable (especially for students) if you find that ease of playing is the better choice for you.

A guitar will never be precisely in tune along the entire fingerboard and across all the strings. Some frets will always be a couple of cents (hundredths of a note) off. The reason has to do with an effect called temperament, which basically involves the amount a string is bent in the vertical dimension to push it down to the fingerboard. The best that you can ever do is to adjust the intonation so that it is reasonably close. The lower the action (or string height), the closer to perfection it will be. This is also the reason that tuning your guitar using the fifth and seventh fret harmonics is less accurate than fretting the notes at the fifth fret (fourth on 'B') for tuning purposes. These are topics for a future How-To note.

Comments? | More Actions Open/Close menu
Apr 03, 2006
HOWTO: guitar truss rod adjustment
by mike (Mike Macgirvin)
Adjusting a Guitar Truss Rod

"The neck on my guitar is warped. I've heard that adjusting the truss rod will straighten it. How do I accomplish this?"

First let's nip this very popular myth in the bud. If the neck of your guitar is indeed warped, there's very little you can do. If it's seriously bad, get rid of the guitar and get another one. If it's an heirloom or collector guitar, be prepared to spend a lot of money to have the fingerboard planed and re-fretted, and you will probably ruin some of the collectable value in doing so. But if it's warped seriously bad, it's not worth much anyway. If you tighten a truss rod too much, you will in fact permanently warp the guitar neck in an often undesirable location.

Now that we've dispensed with the formalities, what's the point of having an adjustable truss rod on a guitar anyway, if not to straighten the neck? Truss rods have evolved over time; and there are many claims that are made about them. But the primary purpose of a truss rod is to have a metal reinforcement piece inside a wooden guitar neck to counteract the strain on the wood caused by the guitar strings. A guitar neck will naturally develop a bit of a concave bow if left on its own for a long enough period of time. A very small amount of concave bow is actually desirable. But the forces exerted by steel strings on the neck usually create an unacceptable amount of bow over time. Some of the first attempts at correcting this bow are still in use today in the form of metal insert strips. That's all they are - metal reinforcement rods - and they work quite well.

Later evolution spawned the adjustable truss rod and recently the two-way adjustable truss rod. These consist of a reinforcement rod anchored at one end and with a tightening screw at the other. By tightening the screw, the tension is increased relative to the wood that it is anchored in. Increasing the tension increases the stiffness. All of this is a long way of saying that the purpose of the truss rod is for reinforcement. It is used to adjust the stiffness of the neck. Somewhere along the line somebody discovered that they could sometimes correct small variations in the neck flatness by tightening the rod - and this led to the myth. The newer two-way rod flexes in both the convex and concave dimensions depending which way you turn the screw. These devices legitimately claim to affect neck flatness, but they do so in a very limited area of the neck.

Will adjustment of the truss rod help you? Only if your guitar neck has a very well-formed natural bow (concave or convex) lying precisely halfway between the neck joint and the nut. If you've got bowing occurring precisely at the neck joint, you have other issues to deal with. If you've got two humps between the nut and neck joint, it's very likely somebody tightened the truss rod way too tight and ruined your guitar. If the neck looks like a roller coaster or is seriously bowed within the first 3-5 frets, it is doubtful that adjustment of the truss rod will have much impact.

Now that you have some background, let's say your neck isn't perfect and you want to do something about it. You open the truss rod cover plate and find the allen wrench with which to turn it. What do you do?

The first thing you should do is loosen the truss rod completely. We will assume for this article that you have a one-way rod. Loosen it until the nut spins freely and all tension is removed. Next turn it back until it is snug, finger tight. If your strings are loose, tune them up at this point. Now using the wrench, turn the nut about one full turn beyond finger tight. The purpose is to apply tension to the neck. That is all that we are doing.

Wood under tension takes time to settle. What you should do now is put your guitar in its case and leave it for about two weeks. That's right, two weeks. You can play it if you want, but don't do any more tweaking until it has had a chance to settle. In fact your guitar is properly adjusted at this point. You can just put the cover back on.

OK, you aren't happy with it and you've come back two weeks later. Put a metal straight edge across the length of the fingerboard. Look at the frets in the middle of the straight edge. If there's a gap, your neck is concave. If there's a 'hump', your neck is convex. Let's say there's a gap. Tighten the truss rod. One half of a turn at most. Leave it for two weeks.

Let's say there's a hump. Loosen the truss rod. One half of a turn at most. Leave it for two weeks.

It's been a month and it still isn't right. What do you do? You can either live with it, or find another guitar. If you're getting noticeable fret buzz when you play, you can raise the string action a bit by adjusting the height of the bridge with shims or adjustment screws. If the last truss adjustment helped a little bit, you can try it one more time. That is absolutely the last time. If you tighten it too tight, you will end up with either a) a double hump in the fingerboard, or b) a broken truss rod. If you are in doubt how tight it is, loosen it completely and start over.

Comments? | More Actions Open/Close menu
Nov 19, 2005
THE IAEA (International Atomic Energy Agency) reports that Iran
by mike (Mike Macgirvin)
THE IAEA (International Atomic Energy Agency) reports that Iran just might know how to make an atomic bomb. They apparently learned how to do it from a bomb maker in Pakistan. The only surprise is that they didn't just get it off the web like everybody else. Unfortunately it isn't rocket science. How do they (try to) prevent the spread of nuclear weapons technology? They regulate three things. 1. Uranium and 2. Really fast centrifuges, and 3. Collimators.

centrifuge.jpg

Here's a centrifuge. Here's what you do with it:

gascentrifuge.jpg

Next we look for an ignition source. From the diagram:

nucfission.jpg

It looks like we need neutrons. In fact what we need is a neutron gun. Here's one -

neutrongun.jpg

Attached to the neutron gun is the collimator. Think of it as a focusing lens for neutrons. It looks like this:

collimator.jpg

Your finished bomb:

bomb.jpg

Comments? | More Actions Open/Close menu
Dec 02, 2007
Aussie Jingle Bells
by mike (Mike Macgirvin)

One of Isabella's favorite songs at the moment... 

Dashing through the bush, in a rusty Holden Ute,
Kicking up the dust, esky in the boot,
Kelpie by my side, singing Christmas songs,
It's Summer time and I am in my singlet, shorts and thongs

Oh! Jingle bells, jingle bells, jingle all the way,
Christmas in Australia on a scorching summers day, Hey!
Jingle bells, jingle bells, Christmas time is beaut !,
Oh what fun it is to ride in a rusty Holden Ute.

Engine's getting hot; we dodge the kangaroos,
The swaggie climbs aboard, he is welcome too.
All the family's there, sitting by the pool,
Christmas Day the Aussie way, by the barbecue.

Oh! Jingle bells, jingle bells, jingle all the way,
Christmas in Australia on a scorching summers day, Hey!
Jingle bells, jingle bells, Christmas time is beaut!,
Oh what fun it is to ride in a rusty Holden Ute.

Come the afternoon, Grandpa has a doze,
The kids and Uncle Bruce, are swimming in their clothes.
The time comes 'round to go, we take the family snap,
Pack the car and all shoot through, before the washing up.

Oh! Jingle bells, jingle bells, jingle all the way,
Christmas in Australia on a scorching summers day, Hey!
Jingle bells, jingle bells, Christmas time is beaut!,
Oh what fun it is to ride in a rusty Holden ute

 

Colin Buchanan / Nick Bland 

Comments? | More Actions Open/Close menu
Nov 30, 2007
The third waterfall
by mike (Mike Macgirvin)

There are three rather spectacular waterfalls within a few minutes of home. Here's the 'little' one...

 

Apologies for the lack of clarity. It's a cell phone picture.

 

Comments? | More Actions Open/Close menu
May 27, 2007
Drakensberg - scenic South Africa
by pierrejacques (Pierre van Eck)
The Royal Natal Park boasts some of the most spectacular South African mountain scenery which includes the Amphitheatre and views of Mont-aux-Sources, where the Orange River has its source. Facilities and ablutions are very well maintained and the variety of walks and hiking trails lead to tranquil areas of immense beauty, unexpected streams and pools where one can bathe in absolute solitude. There is also a trail which leads to the foot of the famous Tugela Falls where the "Tugela plummets 948m in five clear leaps, making it the world's second highest waterfall." An absolutely awe-inspiring return to nature and must-see for any visitor to the region.
 

Hikes range from mild to very challenging and detailed trail maps are obtainable at the Visitors Centre. The range of accommodation options include a camping site which is very economical and within a close, pleasant walk to facilities such as the restaurant and bar. Trout fishing is the main activity for those who prefer not to hike. The pure country air and majestic mountains ensure that the visitor leaves feeling refreshed and generally rejuvenated.

 

 

 

 

Comments? | More Actions Open/Close menu
Mar 25, 2007
Sign of the times
by mike (Mike Macgirvin)

When I was younger and got close to a pretty woman, I would have certain reactions. I'll leave it at that. But don't hang up yet, this post is actually going somewhere...

You know you've been spending too much time in the social networks when you see a pretty girl in the supermarket and your index finger starts to twitch.  You want to click her.

Comments:

Cheryl (Cheryl)
March 25, 2007 16:08
Cheryl
You might have something there. I could always tell when my XBF was checking somebody out because he would started tapping his hand. Now that you mention it, I'm sure it was his mouse hand.

Comments? | More Actions Open/Close menu
Feb 02, 2007
Amusing searches
by mike (Mike Macgirvin)

It's not fair for me to have all the fun reading the website logs. So I've built a page to let others see some of the amusing searches which have led people to this site.

Just go to the new refer page.  Well OK, here's the fine print... There can be some pretty vulgar stuff in the logs, so your account needs to have a non-zero 'Tolerance' setting in the profile to access it.

And the only way this can happen is if you actually have an account and are logged in. Also I am only including search results, and not links from other sites. Sometimes these links can have names and passwords and session ID's and stuff in them and I don't want to compromise somebody's identity just so y'all can have a quick laugh.

The one that really got me laughing today was:

sheet music star wars on the alto saxaphone free nude

 

Comments? | More Actions Open/Close menu
Sep 28, 2006
Lim Jeong-hyun does Pachelbel
by mike (Mike Macgirvin)

Seems that I get about a hundred searches a week for this, so here it is.

 

Comments:

Joe (Derek Joe Tennant)
September 29, 2006 07:09
Joe
Heres a thought..... I've spent a few hours poking around on Second Life. You've heard of it, I know, but I don't know if you've taken a look at it. It seems that people are setting up avatars and storefronts and selling things, and a prime commodity is music. Have you thought of putting some of your music up for distribution? And if not, or if you'd rather not take the time, would you consider licensing someone (me?) to sell a (small) portion of your 'inventory' for a (large part to you) percentage of the take?

 

there he goes....always thining of money again...

mike (Mike Macgirvin)
September 30, 2006 08:01
[*TOP MEMBER*] mike
The stuff that's already out there has been in the public domain for free for so long that I can't fathom trying to charge anybody for it. That said, some new material is long overdue... The MIDI sequenced material takes way too much time to produce - and you're well aware that I've got other priorities these days. Overproduced pop drivel isn't worth the plastic it's burned on anyways. I think I might have to just sit down with a beat-up dobro and a six pack and let the tape run. That's what folks will pay money for.   

Comments? | More Actions Open/Close menu
Jun 13, 2006
Men think about sex?
by mike (Mike Macgirvin)

--- 

When a man and woman meet for the first time, men may be more likely to think about sex -- or at least more likely to admit it.

That's the core finding of a study in June's issue of Psychology of Women Quarterly.

The researchers included Maurice Levesque, PhD. He worked on the study while at the University of Connecticut and now works in the psychology department of North Carolina's Elon University.

---

There are two interesting things about this article:

First that Dr. Levesque apparently talked somebody into funding this research. 

[You know what they say about a fool and his money...] 

The second is that there is a magazine called Psychology of Women Quarterly.

[It's about bloody time...]

Comments? | More Actions Open/Close menu
Jun 11, 2006
Norm's Music
by mike (Mike Macgirvin)

For those folks landing here looking for Sonica Music Company or the Mountain View Music Center, I regret to inform you that Sonica closed down earlier this year - yet another victim of the stagnant Silicon Valley economy. 

However, there is still a music store or three in Mountain View.  I'd like to recommend Norm's at 1901 Old Middlefield Road - 650 968-4800. Here you can find quite a variety of quality musical instruments and expert advice.

Tell Norm that Mike sent you. 

You are also encouraged to use this site for anything related to music in Mountain View or Silicon Valley. Musicians classifieds, instrument advice, etc. I'll be glad to help where I am able. There don't seem to be any other places for local musicians to hang out....

 

 

Comments? | More Actions Open/Close menu
Jun 09, 2006
Ring, ring...
by mike (Mike Macgirvin)

Ring, ring... 

Hello?

You need what? A gold picture frame? Four feet by three feet? And you need it when?

Do you have any idea what time it is?

We open at ten.

Click.

 

Ring, ring...

zarqawi 

Comments? | More Actions Open/Close menu
Jun 01, 2006
Changelog - May 31, 2006
by mike (Mike Macgirvin)

Voting and ranking implemented

This is a rather large body of work. You may now vote on articles and authors and forums and photo albums (in fact it goes way beyond this, but these are implemented today). 

You may vote for as many items as you wish in any or all of the voting categories. The only gotcha' is that you can only vote once for any particular item. Otherwise, it would be called ballot stuffing, which we frown upon. 

Oh, did I mention that you can vote for yourself?

The purpose of this isn't to have a popularity contest, although that is certainly possible. The purpose is to shape the site by virtue of what the membership finds interesting and/or entertaining and/or useful. This is democracy at work. Those items with the highest number of votes will find their way to the top of the lists which contain them. In this way future visitors will find the most interesting content more easily. Anybody providing content can also get an idea of what kinds of content are most likely to be well received.

So all you have to do is click on stuff you like and it automatically makes you a managing editor.     

Comments? | More Actions Open/Close menu
Mar 14, 2006
PHP sessions
by mike (Mike Macgirvin)

This is precisely why I didn't want to use sessions for managing authentication state...

I started to notice my webserver getting really slloooooooow. Sometimes it would time out completely (I've got it setup with 60 seconds max execution time per page). How could this be? I designed the pages for maximum SQL performance. Why is it taking so long to get the database open?

Then I looked closer at the timeout message. Timeout on line 3. Line 3 hasn't even touched a database yet. It belongs to a function called 'session_open()'. Gak.

By default, PHP stores its session data in the /tmp directory. One file per session. I bop over to the session directory and do an 'ls'. It takes about fifteen minutes to list all the session files. I can't even easily count them because the shell chokes on the wildcard expansion. On a Unix filesystem, anything more than 1000 files in a single directory is bad news. It's gotten better over the years, but if you're talking about say 20,000 or 100,000 files, the operating system can't deal with it, plain and simple.

I shortened the session expiration time and made a mental note that this is going to have to be fixed. A couple of days later, timeouts again. This is right after google did a deep scan of my site. OK, something's got to give. So I look at alternatives. PHP can also use 'memory mapped' sessions. No files. OK. That sound like a winner. This is a small site, I shouldn't need that much memory. I recompile php with the necessary configuration and run it. Great. At least it works...

Then I make a mental note that I really need to figure out a way to measure the memory use because running out of memory is not a good thing. And I let it run. I figure about 100 bytes per session. The problem is that I don't know how much memory the mapper reserves for itself and what its built-in limits are. Might be 100 megabytes (roughly a million sessions). Might be a megabyte (roughly 10,000 sessions). I've got about 50 megs free. If it's well written, I should be able to manage a half a million sessions. But I didn't take the time to review the source and find the answers. I just wanted to get it working - pronto. 

Big mistake. I come back the next day and I've got a blank screen. Boy this memory manager doesn't degrade gracefully. When the 'files' driver filled up, the program just hung up for a while. Using the memory driver, the page actually comes up, but there's nothing on it. The dreaded White Screen of Death. At least I now know it's reserving something considerably less than a megabyte - and not asking for more.

OK - now it's done gone and made me mad. Time to write an SQL session driver. Yeah, I know how to do it. I didn't think I'd need it, but it turns out I do. Took about twenty minutes to get it running.


 The lesson here is that you can't use the built-in PHP session drivers even on a small site these days with all the crawlers running around. A few years back you might get a few hundred hits a day if you were lucky. Now it's in the  thousands and tens of thousands.  If you've got a weblog that pings one of the pinging services, you're guaranteed another 500-1000 hits every time you change a page. Since these are all coming from robots and aren't storing cookies, each page is going to get a new session.

So all you developers out there, if you want to use PHP sessions - hack, beg, borrow, or steal a database session driver and figure out how to use it. 

Attached is a little driver I found on the web a couple years back. It's a good starting point if you've never dealt with session drivers before. 

Comments:

John
March 14, 2006 09:43
John
What's the point of keeping sessions for robots? Just curious.

mike (Mike Macgirvin)
March 14, 2006 18:08
[*TOP MEMBER*] mike
Hi John! If you're using PHP sessions 'out of the box', you don't have this level of control. If it doesn't get a session cookie in the header, it creates a new session, regardless. The lifetime of the session storage is set in a config file and is the same whether or not the session is ever reused.

That's the other added benefit of overlaying the PHP session driver - you've got a hook into the storage mechanism and can make decisions on what to keep and what to toss quickly... in fact that's one of the first things I did.


Comments? | More Actions Open/Close menu
Nov 12, 2005
Al-Zarqawi pulled a little boo-boo I think.
by mike (Mike Macgirvin)
Al-Zarqawi pulled a little boo-boo I think. Blowing up people in Amman? You shouldn't mess with the Jordanians. Nope. Also dead were some prominent Palestinians. You really don't want to mess with the Palestinians. And three 'Chinese delegates of the Peoples Liberation Army'. Chinese military. Hope it's merely a cosmic coincidence that they were in the same hotel as the Palestinian 'security personnel'. You really, really don't want to mess with the Chinese...

Believe it was on CNN - an interview with a potential suicide bomber. What I found of interest wasn't that he looked just like any other teenage kid, but that he really, truly believes that his destiny includes the infamous seventy-five virgins. Due to the media that have defined his world, saving oneself for a date with the seventy-five virgins is the crowning achievement of life.

So it seems that the fundamental difference between radical Islam and other religious extremisms is that they are taught to believe in sex after death. Lots of it. Suppose this is to provide a modicum of hope in a culture of arranged weddings with the daughter of the richest person your dad knows personally. What does Christianity say about sex after death? Don't recall that the topic ever came up. Hate to say it, but their heaven looks better than ours...

And this afterlife orgy still takes place if your body is like totally vaporized. In fact, you get more sex if you're vaporized than if you aren't. They've totally got this marketing thing down... Psssstt... kid - yeah you. Feelin' a bit randy? Of course you are... Wife not putting out for you? I see... She's what - 17-18 years old? Wanna' get laid? Tonight? Here, strap on this vest. Don't worry, I'll take care of your widow - I mean wife.

That's the other interesting thing about this social system. You can get killed for casting a wayward glance at another man's wife. But widows (having fulfilled the 'death do us part' clause) are fair game. Having sex with the widow of a martyr is encouraged - as some of her blessed-ness is presumed to rub off. All of this is a very long winded explanation of the dynamics that we are up against fighting these so-called terrorists. We are up against a culture where there are only two sanctioned methods of gratifying wanton lust. 1.) die for Allah, or 2.) recruit people to die for Allah.

Comments? | More Actions Open/Close menu
first  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 last next
Brandy Davis, an outfielder and teammate of mine with the Pittsburgh Pirates,
is my choice for team captain. Cincinnatti was beating us 3-1, and I led
off the bottom of the eighth with a walk. The next hitter banged a hard
single to right field. Feeling the wind at my back, I rounded second and
kept going, sliding safely into third base.
With runners at first and third, and home-run hitter Ralph Kiner at
bat, our manager put in the fast Brandy Davis to run for the player at first.
Even with Kiner hitting and a change to win the game with a home run, Brandy
took off for second and made it. Now we had runners at second and third.
I'm standing at third, knowing I'm not going anywhere, and see Brandy
start to take a lead. All of a sudden, here he comes. He makes a great slide
into third, and I scream, "Brandy, where are you going?" He looks up, and
shouts, "Back to second if I can make it."
-- Joe Garagiola, "It's Anybody's Ball Game"