posts with the tag: php

Posted by: bob on Monday October 17th 2011 2 comments
Tags: extension, geoip, php

During the past few weeks I have been working on a brand new PHP extension to provide an easy object oriented interface for the GeoIP library from MaxMind. The original module (that I did not write) had two main issues. First the directory to find the databases could not be changed except in PHP.INI before PHP loads (so not even ini_set would work). Second was that it was old school and not object oriented. Another issue (so that really makes three) is that it will throw E_WARNINGS for dumb things like records not being found. If there is no record found when you ask for it I would much rather just be handed a FALSE.

[update 2011/10/26] Official GeoIPo manual/documentation is here.

This new one is nearly complete, but I am still waiting to be accepted into PECL. However it works and I have the source available for use on GitHub. Here is a little how-to on how to set up the GeoIP database and use this module.

Why use GeoIP?

  • Perhaps your project has support for English, German, and Polish languages. With GeoIP you can try to guess what country your visitor is from and if they are from a country with a language you support you can set that language default for the user. Things like that go very far towards user experience.
  • If you have a website, I doubt many people can honestly tell me they are not curious what country their visitors are from. GeoIP is an important part of determining your reader demographics. You know all those maps that show dots about where visitors are from? You need GeoIP info to do that.
  • And the bane of all internet users – lets say you are the owner of YouTube/Spotify/iTunes and you need to prevent a certain country from viewing/watching/listening to specific content because of license restrictions. You are going to piss people off, but I guess for legal reasons it just needs to be done.

These are only three of the many valid reasons you might need GeoIP information. Over here I have a page demoing the readout of the server and visitor’s GeoIP info, with a link to the visible source at the bottom.

Continue reading about setting up and using php-geoipo

Posted by: bob on Friday October 7th 2011 no comments
Tags: development, evolution, framework, php

From explosm.net
from C&H explosm.net

For the past  year one of my side-not-so-side projects has been the zen\this Framework. Technically the project is even older than that. It was started because many years ago I wrote a Database library for MySQL that I really liked. It wrapped mysql/mysqli into what I consider a much more common and better interface. At the time it was designed to be portable to any codebase and handle things like injection protection without me or the other developers (who were at the time, interns) spacing about it. When I decided to write additional libraries the design challenge was to mimic the original design pattern of that database library.

The interface was quite simple. The main database class was a series of static functions, and there was a query object class too. This was before we had namespaces in PHP so the main database class was really just being used as a namespace. Configuration options were placed in a static array, database::$config, and most of the functions referenced that when deciding which database to query as it handled multiple connections.  This worked great as a completely stand alone library but after it evolved into the current edition in zen\this there have been some design issues.

Continue reading about the evolution of that database library…

Posted by: bob on Tuesday May 24th 2011 no comments
Tags: php, typecast

Twice now this week, which is impressive as it is only Tuesday, questions about variable types have popped up on IRC chat about how strings get evaluated and converted. PHP has the soft variable type system that allows you to do things like compare strings to integers, or take a variable that used to be an integer and store a string in it instead. This is unlike the strict typing of languages like C where when you create an integer variable, you better not be trying to store anything except an integer in it.

To hopefully clarify things for more people and also create a link I can send instead of re-explaining it every time, lets take a look at comparing and converting strings.

Continue reading about comparing and evaluating strings…

Posted by: bob on Tuesday May 10th 2011 no comments
Tags: function, namespace, performance, php

To continue on with the previous post, On the speed of functions and namespaces, it was brought to my attention that namespaces should be faster with aliasing. Also how does it compare to static functions? The news was not good for either. Another thing that was brought to my attention that to avoid a lookup when in a namespace functions like filter_var should be absolute referenced, so we/I tried that too.

Continue reading to see the additional test

Posted by: bob on Tuesday May 10th 2011 2 comments
Tags: function, namespace, performance, php

My day started off fairly simple, I wanted to write a function that could take a string of things like “True” and “Yes” and return boolean true, thusly “False” and “No” would return me boolean false. PHP has a function that can handle the basics of this already, filter_var, however it only works on variants of true and false, not yes or no. Keeping with PHP’s strtolower and strtoupper naming I named this function strtobool and stuck it in my utility function namespace.

I then compared it speedwise to the built-in filter_var function, even though filter_var cannot do what I want at the scope I want it – it would still be a good test to see if it was even worth supporting “Yes” and “No”. Here are the results of that test.

Continue reading about the speed of PHP functions and namespaces

Posted by: bob on Wednesday May 4th 2011 no comments
Tags: coda, namespace, php

If you develop on a Mac, chances are you might have at least heard of Coda if not already fallen in love with it. It has been a while since they updated it, and I have submitted a few feature requests including Namespace support for the default PHP syntax mode. They mailed back thanking me and said it has been filed, but still no updates. So I decided yesterday to take matters into my own hands.

It could not be too difficult since they support third party syntax modes, but rather add a new PHP mode I wanted to edit the default one already configured. It was easy, and here is how I did it.

 

Continue Reading…

Posted by: bob on Thursday March 10th 2011 no comments
Tags: dallasphp, framework, php

At the DallasPHP meeting this month I gave a presentation called “Building from the Ground Up, Can Has Framewerk?”, where I discussed a bit about what gives a code framework its structure, highlighted a few popular frameworks, and then discussed provisions you should think about when planning to build your own framework from scratch.

To my suprise, the presentation lasted just over an hour and had some good question/answer time afterwards. Unfortunately the camera we used to record the meeting uses a FAT file system (or something) and quit recording after the file hit 4GB, cutting off the last 20 minutes or so of the presentation.

Here are the slides and demonstration code I used for the presentation!

Posted by: bob on Wednesday March 5th 2008 no comments
Tags: apache, config, gtk, help, php, php-gtk, web

PHP-GTK. Anyone who uses Linux often enough probably recognizes the two acronyms there. It sounds like a gift from the deity of choice to anyone who uses the PHP language frequently. PHP (Hypertext Preprocessor) as it stands to most people is one of the most common programming languages used today… on the web. Most are familiar with the need to have a web server with PHP so applications like forums and blogs can be run. The funny thing is that 99% of the people using PHP have no idea it really has nothing to do with Apache (the most common web server application), or that PHP does not even need a web server to run.

That number might be high, I just made it up, it could be closer to 98.9%. In any case this is the most frequently encountered problem we run into when trying to help people get started with PHP-GTK.

Let me get it out right now, PHP does not need a web server to be used. PHP does not need Apache. PHP does not need anything but itself. Thanks to the thing called the Command Line Interface (CLI, or PHP-CLI) you can write a PHP script to do things on your own computer just like a Bash script or Windows Batch file. Check out this from my Linux terminal window:

Continue Reading…