PHP

Mac OS X Snow Leopard, PHP, MySQL, SVN, Xcode, and Me…

With minimal effort, I was able to get the PHP bundled with Snow Leopard to use the PHP extensions that I had compiled for xdebug, imagick, and magickwand to run in 64bit mode.

Snow Leopard comes bundled with Apache 2.2.11, PHP 5.3.0, and SVN 1.6.2.

I upgraded my MySQL install from 5.0.77 to 5.1.37 and then moved my data folder to another location to help keep things sane using the /etc/my.cnf file.

I installed the Xcode from the Snow Leopard CD and downloaded the iPhone SDK 3.1 Beta 3 for Snow Leopard.  Slightly different interface, but I welcome the changes.

So now, instead of using external packages for SVN and PHP (Entropy), now I’m using the prepackaged bundled software.  I did have to reconfigure my svn connection in Apache as it got toasted in the upgrade to Snow Leopard.  It wasn’t a problem though as it was only a few lines.

Now I can sleep good, I hope.

VN:F [1.9.22_1171]
Rating: 7.3/10 (4 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 4 votes)

Mac OS X Leopard, Entropy PHP and XDebug Extension (64bit)

As all my entension in PHP must be compiled in 64bit to load into PHP, I’ve decided to give the details on how I added xdebug to Entropy PHP 5.2.5 beta 6 on Mac OS X Leopard running on an Intel Core 2 Duo.

First, download the source code for xdebug at the following site

XDebug (source code [2.0.4 as of this writing])

Then unpack the file into a directory someone on your system.

From the terminal, go to the folder where you unpacked everything. It should be xdebug-2.0.4. Then type the following commands:

  • cd xdebug-2.0.4
  • phpize
  • MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load” ./configure –enable-xdebug
  • make

Now wait for it to complete the compiling process.  When it is done, begin these commands:

  • cd modules
  • chown root:wheel xdebug.so
  • sudo mv xdebug.so /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/
  • cd /usr/local/php/php.d
  • sudo pico 50-extension-xdebug.ini

In the text editor, type the following line, then save the file with Control-O (WriteOut), then exit, Control-X.

zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so

Once you’ve save the file and returned back to the terminal you can type in the following to restart Apache2:

  • sudo apachectl graceful

To make sure all went well, type in this to see if Xdebug is showing in the PHP information.

  • php -v

Should display something like this.

PHP 5.2.5 (cli) (built: Jan 24 2008 00:33:14)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Xdebug v2.0.4, Copyright (c) 2002-2008, by Derick Rethans

If the Xdebug v2.0.4 line shows up, then you’ve succesfully installed the 64bit version of Xdebug for Entropy PHP in Mac OS X Leopard.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Expression Engine = Work For Me

Began working for a Grand Rapids firm to modify extensions in Expression Engine. I’ve been helping to modify existing code and to convert so javascript to jQuery.

Hopefully work stays current and often. As I really enjoy the work and the fact I’m no longer jobless.

Doing all this as a freelancer from the basement of where I live, about 50 miles away from the firm.

Thanks for giving me work to do Ryan. I really needed it.

- Xeon

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

PHP Test From Job Recruiter Today.

This is the text I got from a job recruiter today, to make a PHP script to do as they required for a possible job.  Mind you, if you submit the php test to me, and don’t include any NDA, I will most likely post the test, and my results on the internet.

Write a PHP function that determines if an IP address is contained within a list of CIDR blocks. The function should return a boolean. This is the function signature:

function ip_in_cidr_list($ip, $cidr_list)

Example call:

$ip = “216.21.215.10″;
$cidr_list = array(“216.21.208.0/20″, “192.168.0.0/16″);
ip_in_cidr_list($ip, $cidr_list)

For bonus points, provide some test code that demonstrates your function is working correctly.

Here is my code results for the test:

/*
XEON XAI
http://www.xeonxai.com
Copyright 2008 Xeon Xai
2008/09/30 04:28PM
*/
 
// Construct array for IP addresses to check
$ip_list = array();
 
// Initial IP address to check.
$ip_list[] = "216.21.215.10";
$ip_list[] = "192.168.0.1";
 
// Add in additional random IP addresses to make it a total of 10 that are checked.
for ($i = 0; $i <= 7; $i++) {
    $ip_list[] = RandIPAddress();
}
 
// Construct array for CIDR list.
$cidr_list = array();
 
// Insert into CIDR list.
$cidr_list[] = "216.21.208.0/20";
$cidr_list[] = "192.168.0.0/16";
 
// Do CIDR check.
for ($i = 0; $i < count($ip_list); $i++) {
    $verify = ip_in_cidr_list($ip_list[$i], $cidr_list);
 
    if ($verify == false)
        echo "IP: ".$ip_list[$i]."\n\rFail: Not in range of the CIDR\n\r";
    else
        echo "IP: ".$ip_list[$i]."\n\rPass: In the range of the CIDR\n\r";
}
 
// CIDR checking function
function ip_in_cidr_list($ip, $cidr_list) {
    foreach ($cidr_list as $key=>$value) {
    // BLOCK ==> $cidr_list[] as $value
        list($base, $bits) = explode("/", $value);	// Split IP address from Mask
        list($a, $b, $c, $d) = explode(".", $base);	// Split each subsection of the IP address.
 
        // Break down the bits.
        $net	= ($a << 24) + ($b << 16) + ($c << 8) + $d;
        $mask	= $bits == 0 ? 0 : (~0 << (32 - $bits));
 
        // Low region in IP range.
        $low	= $net & $mask;
 
        // High region in IP range.
        $high = $net | (~$mask & 0xFFFFFFFF);
 
        // BLOCK ==> $ip
        list($a, $b, $c, $d) = explode(".", $ip);		// Split each subsection of the IP address.
 
        // Break down the bits.
        $check = ($a << 24) + ($b << 16) + ($c << 8) + $d;
 
        // If IP address matches in CIDR range, return true.
        if ($check >= $low && $check <= $high)
            return true;
    }
 
    // Will only return false if never first returned as true in above foreach loop.
    return false;
}
 
/* Function to create random IP addresses, that will most likely be out of the range of the scope of the CIDR check system.
Most commonly, they will result in a FAIL message.
Very few, will result in a PASS message.
 
Tests from ./php | grep Pass:
 
Results from 10 IP address, with 2 static, 8 random.
MacBook:cidr Xeon$ /usr/local/php5/bin/php index.php | grep Pass:
IP: 216.21.215.10 Pass: In the range of the CIDR
IP: 192.168.0.1 Pass: In the range of the CIDR
 
Results from 10,000 IP address, with 2 static, 9,998 random.
MacBook:cidr Xeon$ /usr/local/php5/bin/php index.php | grep Pass:
IP: 216.21.215.10 Pass: In the range of the CIDR
IP: 192.168.0.1 Pass: In the range of the CIDR
IP: 192.168.18.45 Pass: In the range of the CIDR
 
Results from 100,000 IP address, with 2 static, 99,998 random. (After 3rd run)
MacBook:cidr Xeon$ /usr/local/php5/bin/php index.php | grep Pass:
IP: 216.21.215.10 Pass: In the range of the CIDR
IP: 192.168.0.1 Pass: In the range of the CIDR
IP: 192.168.26.138 Pass: In the range of the CIDR
IP: 192.168.189.88 Pass: In the range of the CIDR
*/
 
function RandIPAddress() {
    $randIP = "";
 
    for ($i = 0; $i <= 3; $i++) {
        if ($i > 0) {
            $randIP .= ".";
        }
 
        $randIP .= rand(0, 255);
    }
 
    return $randIP;
}
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)