Looking into phpShop

Well, I just grabbed a small contract to tweak some stuff in an online shopping cart called phpShop. I have had quite a few run-ins with a huge variety of carts written in PHP, and by and large they have been horrible. OScart is a train-wreck, zen cart is not pretty, but is survivable. So far though, phpShop looks sharp, clean and well written. It does seem to be a bit lightweight, but most of the time thats a good thing not a bad one. As I keep going on this, I will review phpShop in more detail.

Introspective Debugger — the basic structure

So the first thing that this script does is decide which instance of the script it is. What I mean by this that this page now loads completely diffrent code and behaves differently depending on what the situation is.So by default when you load the page, its going to generate an ID number (which will be used as a high port), load a very simple frameset, and then die

if(!array_key_exists("idbg_mode",$_GET)){ /* Display Frame Mode */ echo("<html> <frameset rows='65%,35%'> <frame src='$callBackName"."cnc' name='infoframe'> <frame src='$callBackWvars"."run' name='scriptframe'></frameset></html>"); exit();

each of the two frames within the frame set then calls the same script, but passes variables to it that drastically change its behaviorOne of them calls with the cnc option (command and control) and one of them calls with the run option, which tells the program to go ahead and run, with the degbugging code active.In each case, the instances are passed (as a get variable) the instance id that was generated with the frameset, which is how they know what port to find eachother on.

I’ll go into how CNC works, and how the processes talk to eachother a good bit more in later posts, but for now I want to look at how the “run” instance works. Run depends on a very obscure php language feature called “register_tick_function” which allows you to set a function that will be run every X statements that are viewed.in addition to registering the tick function it is necessary to start the ticks firing by using the line declare(ticks=1);Honestly I’m a little curious why this languge feature is in PHP at all, but its there, So I think I might as well use it. This is also the feature that was the inspiration for the whole damn project.So the very Astute among you might notice that I do not ever actually call declare(ticks=1), but instead require the user to put it in there code right after they include my file, which is horribly inelegant. Why you might ask?As it turns out the declare statement (possibly only with refrence to ticks, but ticks are the ONLY thing that you can use the declare statement for currently, I guess we will find out if this is universal when we move on to php6) seems to only apply to includes at the same depth and lower in the file inclusion tree as it.This means that since you are including my file in your file, my file is at depth 2 and your file is at depth 1, if I put the declare statement in my file, it will not apply to your file, though it will start applying to any other files that you include. This problem is not documented, and honestly drove me batty for a good long time, because it generates such strange behavior.

else if (array_key_exists("idbg_mode",$_GET) && $_GET["idbg_mode"] == "run"){
echo ("<h1> I am running DIV $idbg_id </h1>"); register_tick_function("idbg_tick_function");}
I need to cover a lot more of what happens at each tick, but I want to keep each post pretty short, so I’m going to save that for tomorrow.In the meantime I should try to get some paid work done.

The most Interesting Code I Have Ever Written

I wrote this about a month back, and Honestly blew my own mind with it. Its far from the best code I have ever written, something which is further exacerbated by the fact that I was shooting to keep it short and small, which never makes your code good, I was also aiming not to use anything that is not a core function in PHP. The flip side is that I used a lot of really uncommon php calls that do some very, very cool things. At one point this was an ajax app, but I discovered that it could be smaller and cleaner by just using frames.

This will be the first post in a series where I go through this code and explain it, and some of the cooler calls that it is using, as well as some advanced php and programming concepts. But for now I’m just going to give a one paragraph overview of what the code does and get it into the post. There is one other file which I will also post and explain at some point.

So read On to take a look at the nitty-gritty, and get a feel for what it does in total
Continue reading The most Interesting Code I Have Ever Written

Totally Hosed My Dev Environment

So I have been trying to play with the Zend Framework, which by all accounts is pretty cool, and trying to get it set up on the dev environment that I have here on my cute little macbook. Sadly, for some reason the version of os X 10.5 that ships with it doesn’t have pdo_mysql support installed (though it has pdo_mysqllite ?? I mean, come on, seriously?) So it’s off to the recompile mines. Sadly, once you recompile PHP you need to recompile Apache, which wouldn’t be a big deal at all other than my not knowing about it and it not giving me anything like a coherent error message regarding this. Fine, whatever….

Next, I discover that I can’t user the PEAR auto-installer, because it can’t find the damn modules directory, and neither can I. I have even tried making new ones in every likely place. What’s worse, I seem to have also lost traditional MySQL support as well.

I’m getting pretty annoyed with OSX here, It’s a damn nice client OS, but it’s driving me nuts on the server side. (Still better than Windows, it’s just a bit like the The Twilight Zone, things are close enough to where they should be to make you think that you know what’s going on, but when you try to actually do something….)

I guess I’ll try MAMP now. I have been meaning to look at that anyway.