Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.

Archive for March, 2008

APC (Alternative PHP Cache) on Debian Etch

Posted by chris on March 26th, 2008 Comments(0)

This is one of the best packages you can incorporate into your web development. Basically APC allows you to cache data in memory for extremely fast data access. We are exploring writing an application at work the must have extremely fast access to data, so fast that we are willing to dedicate a server with lots of RAM to this application. Are other alternative is to store the data on XML files with small yet very fast disks that spin at high RPMs, with lots of onboard disk cache, most likely a SAS or SCSI disk. This would allow for fairly quick access as the disks would spin fast and be small so seek time etc…

Honestly both servers would come out to within a few hundred dollars of each other. So the memory-based solution utilizing APC in PHP is probably the best. So tonight I installed APC on my home server, a dual core xeon 2.6 Ghz server with 3 GB of RAM, and 4 SCSI disks in RAID 5, with the OS stored on 2 18 GB disks in a mirror. Yes I am a fucking geek. Would’ve like to have done this on my beta server (geek again), but it only has 1 GB of memory and I intend on storing that much data in memory :)

So here is my experience and how to with APC

Read the rest of this entry »

In Linux, Programming (, )

Javascript 2.0

Posted by chris on March 22nd, 2008 Comments(0)

This was posted to slashdot. I’d personally like to see Javascript get closer to C style languages as thats what I am most familiar with , the part that scares me though is backwards compatibility with ancient browsers. JavaScript is already a nightmare with browser compatibility.

http://blog.jeremymartin.name/2008/03/web-20-meet-javascript-20.html

In JavaScript and Ajax ()

Getting Your SMTP Server White Listed

Posted by chris on March 15th, 2008 Comments(0)

I used to operate a website that requires users to validate accounts. Unfortunately my email server was looked upon as a spam server. Though not blacklisted providers such as AOL and MSN/Hotmail were sending my emails directly to users spam folders. Luckily there are steps you can take to prevent this:

Setup reverse DNS
Contact your ISP about setting up a reverse DNS record. This only takes a couple of minutes but it has the biggest impact on legitimizing your email server. If your ISP is like mine they will have a web based management console that makes the process idiot-proof.

Setup an SPF record
MSN/Hotmail as well as other email provides are big on this one. openSPF has a wizard that creates your SPF record for you. You’re domain registrar should have an option to add this record into your account or you can add it into your BIND or other DNS server.
http://openspf.org/

Contact AOL directly
You can contact AOL directly about getting on their “white list.” I was amazed by their response time, I was on their whitelist within 24 hours.
postmaster.aol.com/

Contact MSN/Hotmail
Microsoft also has great response time.
http://postmaster.live.com/Services.aspx

Other
Make sure your email server is not an open relay. The easiest way to do this is to restrict sending of emails via your server to the localhost and then use a web-based MTA such as squirrelmail or roundcube. Create some test accounts on gmail, yahoo, aol, and msn to see if your emails are going into spam folders. If they are then get in contact with these providers and see what you can do to resolve the issue.

In Linux (, )

Pass Objects and Arrays Between JavaScript and PHP with JSON

Posted by chris on March 13th, 2008 Comments (2)

In this article I gave a brief intro to using JSON to pass JavaScript arrays to PHP via Ajax. I’ve done a bit more with json since then and with the help of a co-worker discovered how to get javascript objects working together with php utilizing json.

Passing Multiple JavaScript objects to PHP

JavaScript class:

1
2
3
4
5
6
function product(id,name,price)
{
	this.id=id;
	this.name=name;
	this.price=price;
}

Above we just create a simple javascript class that we will call below.

Putting JavaScript objects into JavaScript array:

1
2
var object = new product('222','spectacular fizz','3.59')
var productsArr[productsArr.length] = object;

We can now add as many of the these objects as we would like to the products array. So lets say we have an array that looks like this below…

1
2
3
productsArr[0] = object...
productsArr[1] = object...
productsArr[2] = object...

…and we want to pass it over to PHP. So we use the following code to turn it into a JSON string.

1
var productsJSON = JSON.stringify(productsArr);

Now we need to do an AJAX Post and on the PHP side we decode the JSON string (note you only need to stripcslashes if magic quotes its turned on):

1
$productsArr = $this->json->decode(stripcslashes($productsJSON));

Now we can reference these objects multiple ways. One if we are just continuously looping through we can use a foreach:

1
2
3
4
5
6
foreach($productsArr  as $product)
{
	echo $product->id;
	echo $product->name;
	echo $product->price;
}

Or of course we can reference the object directly by its index in the array.

1
echo $productsArr[1]->name;

Pretty cool huh.

In JavaScript and Ajax, Programming (, , )

slimbox

Posted by chris on March 8th, 2008 Comments(0)

Pretty slick way for making a thumbnail viewer. This works in the following browsers: Safari (windows), FireFox 2 (windows), Internet Explorer 7, Internet Explorer 6, and Internet Explorer 5.5.

http://www.digitalia.be/software/slimbox

In JavaScript and Ajax ()