Tuesday, November 13, 2007

PHP CGI Weirdity

I don't know why anyone would ever want to programmatically call the CGI version of PHP, but there's a slight weirdness you'll have to deal with. If you call it with just the normal CGI environment variables, PHP will complain that it was compiled with "--enable-force-cgi-redirect," and that it needs some extra stuff.

Here's that stuff:
1. REDIRECT_STATUS. I just set this to 200, and it seemed to work. Pretty sure that refers to the HTTP status, but I really haven't researched it at all.
2. PATH_TRANSLATED. This is just the location on disk of the php script to run.

Setting these two seemed to work, but (just for kicks) I also set REDIRECT_URL = SCRIPT_URL = REDIRECT_SCRIPT_URL = the URL (minus the server name, ie "/dir/script.php".)

Monday, November 12, 2007

Fun With PERL

I'm pretty proud of myself right now, because I just used PERL to do something cool. In my 360 class (CS 360 - Internet Programming) we're building a web server, and I keep finding new mistakes of mine to fix. It's going well, but there seems to be some kind of limit in Linux to the number of semaphores I'm allowed to create. So when my program dies a few times (without removing the semaphores it created), it won't create semaphores on restart. Up till now, I've been restarting the computer when this happened.

Did some investigating, and I found out that there's a nice little utility, ipcs, that prints out all the IPC (interprocess communication) stuff - message queues, shared memory, and (of course) semaphores. There's another nice little utility, ipcrm, that removes IPC stuff.

I could go through and remove all my semaphores every time, OR I could use my newfound PERL knowledge to make the computer do it for me. Being a geek, I found the second option way cooler.

Anyway, here's my code. Enjoy! (Note that I don't guarantee it on anything. Also, note that it deletes ALL semaphores under your user. So don't run this if anything else you're running is using semaphores. Finally, use this at your own risk!)


#!/usr/bin/perl

open(IPCS, "ipcs|") || die("Couldn't run ipcs.\n");

$startedSems = 0;
while (<IPCS>){
if ($startedSems){
if ($_ =~ /------ Message Queues --------/){
$startedSems = 0;
}
else{
($currkey, $currid, $usr) = split /\s+/;
if ($currid != "" && $usr eq "yourUserNameHere"){
$cmd = "ipcrm -s " . $currid . "|";
open (IPCRM, $cmd);
while (<IPCRM>){
print;
}
close(IPCRM);
print "Removed sem id=$currid\n";
}
}
}
else{
if ($_ =~ /------ Semaphore Arrays --------/){
$startedSems = 1;
}
}
}
close(IPCS);


Oh yeah, two more things. Change yourUserNameHere to your user name. And last of all, either chmod a+x the file to make it executable, or perl it.

Monday, November 5, 2007

Quit Stealing

Is stealing from thieves different from stealing from honest people? In the words of Futurama's Lrrr, "Yes; but not by enough."

The companies in the recording industry are unabashed crooks. That they steal artists' rights in legal ways is completely irrelevant.

But their status as weasels doesn't excuse those who steal music. Unless it's an act of civil disobedience, stealing music is wrong.

Record company executives: change, or go to Hell. You are thieves.

Musicians: license with Creative Commons. Record companies are obsolete.

Saturday, November 3, 2007

My Search Terms

Thanks to Google Analytics, I know that about half the people who visit my little blog are actually just seeking guitar tabs to the Jonathan Coulton song Code Monkey. Then they promptly leave for the good reason that I don't have any Code Monkey guitar tabs (or any guitar tabs, for that matter).

So to appease the masses, here are some links. Here's Jonathan Coulton's Code Monkey page - just click on the Guitar Tabs tab. Also, there's a link on that page to a pdf with an actual tab. It seems fairly accurate to me. When I get a break from school, (and when I finish my guitar tab xml DTD and XSL) I'll make an attempt at doing one myself. Enjoy.