Author: ccornutt

A Look Back from 10k

It’s funny – I only realized a few days ago that the 10k post was coming up. You get so used to just wring the posts day after day that you don’t even really notice the numbers. Each thousand along the way has definitely been a milestone, but reaching ten thousand posts to PHPDeveloper.org really feels like an accomplishment.

I started the site while I was back in college. A friend of mine at the time (who I now work with once again, woo!) introduced a young Perl programmer to the wild world of web programming. When I headed out to college I had a basic idea of how the web worked and what it was. I knew there was value in it and not just in the business sense. There was this feeling that I could put my fingers to the keys and make things – things other people could look at and enjoy. When I learned about PHP, my interest grew and I read everything I could and looked at every site even remotely related to PHP. The more I really got into it, the more I wanted to share the things I was finding with the whole web (or at least the part that would want to read it). So, in one late Texas summer, the phpdeveloper.org domain name was bought and I set up shop on a little 486 there on the school’s network….it pays to be friends with the network admins.

Back then I would only post once a day – it’d gather some of the things that I thought were useful and write a summary, mashing them all together. I worked on the site (then in PHP3) and used it as a learning experience to grow in the language. Terms like “CMS” and “abstraction” started to come into the picture and soon PHP4 burst onto the scene in a big way. The site got its first major rewrite then, adapting to this strange and new object oriented setup the language now offered. I created my own little set of libraries to use for the site and whatever other projects that bled over on the sites. The number of hits that the site was getting was growing and the little 486 had to be retired for a dual Celeron 266 machine in my apartment. It kept the room hot but it served up the pages well.

Fast forward to just a few years ago and you’ll find PHPDeveloper.org sitting on a dedicated server, graduating up to the “big boy” world. The site’s been through two more major rewrites (one with the Zend Framework and the other recently with Solar) and have moved hosts once again to where it lives now (Slicehost).

I’ve had tons of help from others in the PHP community out there over the years – people like Davey, Eric and Ben that have posted for me what I wasn’t even remotely close to an internet connection. There have also been lots of supporting players over the years and, more recently, people from the community offering suggestions and sending in news submissions and leads to follow.

PHPDeveloper.org has always been about sharing the best and latest from all around the web to the PHP developers out there and I have no plan of stopping any time soon. As long as the PHP community thrives (and lets face it, it’s not going anywhere) the site will be right there along with it with plenty of news, views and community thoughts as they happen.

Thanks to all for the support to make it to 10k – here’s to hoping for 10k more!

PHPDeveloper.org Sees the Light – The Move to Solar

So I’ve been asked several times about the move I made for PHPDeveloper.org from the Zend Framework over to Solar with the main question being “why?”

Well, I hate to break it to any of the framework zealots out there but the only real reason I had for doing it was the old “try something new” idea that floats around every so often. Yes, I know the site was working just fine under the old Zend Framework code (and yes, I do mean old – I think it was a few versions before 1.0 even) but I get the itch to do something new every once and a while. Some people redesign – I’ve done that too – and others rewrite things from scratch.

I took the opportunity to really look at the core of the site, stripping out all of the extra little “goodies” that I’d hacked in to the ZF version to get various things working. I came back to the primary focus of the site – to provide the latest news information quickly and easily – and made sure that all new code pointed toward that goal. The overall concept is a simple one really: it’s essentailly a blog whos topic just happens to be the goings-on of the PHP community as a whole. All it really needed to do was show the news items, serve up a feed and provide an administrative way for me to add new posts to the system.

I developed the Zend Framework version many moons ago and I almost don’t remember how it was all set up. It took me a bit to get back into it to see how things were structured, but in the end, most of that was tossed and replaced wth some sleek Solar code.

One of the biggest things that I was happy with in the new rewrite was the way that the news information is fetched from a the database. There’s no longer function calls like “getMainNews()” or “getNewsDetail()”. Instead they were replaced by a fetch function that takes in parameters on the object (sort of like the Command design pattern) and applies them to the current query.

For example, I make a call to the “setProperties” function of the NewsAPI object to tell it that I want a type of “where” with a value of “ID=1234”. The fetch function then looks through the properties and applies the operation to the query. The result is a function that can be called the same way every time with the same sort of output. The only difference is in how much/what kind of output there is.

I was concerned about some of the performance issues I was seeing on my server when I made the switch. Some of it was my own fault – forgetting to cache the feed instead of geenrating it, not adding the spam/IP filtering to ward off some of the spammers – but there was still a slow down when the load started to get high. I knew Solar could handle it (it had done it wonderfully on the dev server) so it had to be something else. The dedicated machine I’d been using was nice, but was showing some of its age. I decided to buy a slice from Slicehost and set up shop over there with only PHPDev running on it. Turns out that it wasn’t the new Solar version that was the issue, it was the server. In fact, I’d almost be willing to not cache the feed anymore – the performance is that good.

My last little part of the transition is writing the backend command-line scripts that I use to do some automatic things and the site will be back and complete and 100% Solar-ized.

I know there’s some things I didn’t cover here, so if you have any questions, leave a comment or drop me a line: enygma at phpdeveloper dot org. I’m more than happy to talk Solar with you. And if you’re interested and want to chat with other Solar folks (including some of the main developers behind it), come over to the freenode network – irc.freenode.net – and pop in to #solarphp and say “hi”.

SolarPHP.com

Running a remote script over ssh from EditPlus

I came up with something handy for EditPlus users out there who might need to execute something on a remote machine (like say the linux box that has the samba share your files are being accessed throught).

My situation is that we use templating on all of our files that needs to be regenerated each time there’s a change made. Previously, this meant having two windows open – one for EditPlus and another that’s a ssh session at the directory you’re working with. Well, in one of those “surely there’s a better way” moments this morning, I did some digging and came up with this process:

– Using the “user tools” in EditPlus, create a connection to a remote machine
– via plink (Win) to ssh to the machine
– and execute the command over that interface

#mylist li { margin: 5px; }
Well, it look a little PHP trickery to get it working exactly right, but here’s how:

  1. Download plink
  2. In EditPlus, go to Tools -> Configure User Tools
  3. Hit “Add” and choose “Program”
  4. Change the program name (in the “Menu Text”) to your liking
  5. Add the command to execute in the Command box.
    In my case, I wanted to connect to the remote machine over ssh and run the command to retemplate the file I was working on. Here’s what I put:

    plink.exe user@server -pw mypass /usr/local/bin/retemp.php
  6. Add an argument
    I put the value of ‘$(FilePathNoDrv)’ in there (yes, with the quotes) to append the path to the file without the drive letter
  7. Click “Capture Output” and “Save open files”
  8. Hit “Ok” to save the changes

Then you can check your Tools menu to see what the keystroke for it is and voila – you’re all set. It’s nice that it gives the option to save the file when you execute the tool. Anything that makes for less keystrokes for me!

The PHP script on the other side had to do a little something to handle EditPlus’ input correctly – here’s the example:

#!/usr/local/bin/php

$in=file_get_contents("php://input");
exec('/usr/local/bin/template.sh /www/web/'.str_replace('\','/',$_SERVER['argv'][1]),$out);
//print_r($out);

I left that $out in there just in case you might need to have some debugging output. Because of the way that the script passes in the values (it is a Windows software after all), we have to switch around the slashes to work with the linux file system. So, if in EditPlus my path is like H:wwwdocrootmyfile.tpf the script will map it over to /www/docroot/myfile.tpf and run the template.sh on it to retemplate it.

There we go – hope it’s helpful!

Fixing “Cannot get media type from ‘0’”

By the way, if you ever see lots and lots of lines in your Apache logs like this:

[warn] Cannot get media type from ‘0’
[warn] Cannot get media type from ‘0’
[warn] Cannot get media type from ‘0’
[warn] Cannot get media type from ‘0’
[warn] Cannot get media type from ‘0’
[warn] Cannot get media type from ‘0’

(specifically if you’ve upgrade from Apache 1.x to Apache 2.x) you need to add the following to your httpd.conf:

TypesConfig /etc/mime.types
DefaultType text/plain

For some reason, our Apache 1.x files didn’t have that in there and it’s apparently required by Apache 2.x for correct mime type handling.

Being Binary in SOAP

Well, it might not be the best way to do it, but here’s a way I found to send binary data via PHP’s SOAP extension from one place to another:

Server:

function recieveFile($data){
	$data=base64_decode($data);
	$path='/my/file/path/img_out.gif';
	$fp=fopen($path,'w+');
	if($fp){ fwrite($fp,$data); fclose($fp); }

	return strlen($data).' written';
}
$input	= file_get_contents("php://input");
$server = new SoapServer(
	'http://[my url here]/binary.wsdl',
	array('encoding'=>'ISO-8859-1')
);
$server->addFunction('recieveFile');
$server->handle();

and the Client:

ini_set("soap.wsdl_cache_enabled", "0");

//send binary data
$client=new SoapClient(
	'http://[my url here]/binary.wsdl',
	array('encoding'=>'ISO-8859-1')
);

$data=file_get_contents('/my/file/path/img_to_send.gif');
$ret=$client->recieveFile(base64_encode($data));
print_r($ret);

It’s pretty basic – the client just reads in the file’s information, runs it through a call to base64_encode before it’s sent off to the server. Once it’s there a mirror call to base64_decode gets the content back to normal and it’s written out to the “img_out.gif” file on the remote server.

It’s probably not the best way to do it, but its one that I’ve found that works quickly and easily. I tried to just send the binary data without base64 encoding it and it didn’t want to cooperate (it was only getting the first chunk of data). I don’t know how well it’ll perform with larger files, though – we shall see.

My Day of Advent – Dec 10th

Lookit! It’s me!

Chris has posted my contribution (self-promotion?) to the Advent Calendar for this year – my (not so brief) look at planning your applications. Thanks to Chris for including me on the list for this year’s calendar (there’s going to be more, right?)

I got to try out the new photo editing in Flickr to make the picture for it – works pretty well for being web-based.

In the way of a personal plug, besides the holiday themed calendar version of each of the days that Sean’s created, I’ve also been keeping up with each of them in a post over on PHPDeveloper.org.

28 Days Later

Well, unfortunately, this year’s Nanowrimo has come to an end and I’m just over the halfway mark on my “piece of literature”. I started a little late – the 2nd – so it’s been a catch-up game since. It’s been an interesting experience so far and different than I thought it would be. I suppose I’m too used to writing to more technical things – tutorial copy only has to explain what’s already there – and not things that are plucked right out of nowhere. I can do short fiction (have in the past, at least) so I thought I’d try my hand at taking the month to work up what I could. I only really got the chance to work on my lunch breaks, so I didn’t think 27k-ish was too bad.

So anyway, here’s a few things I’ve learned from the experience. I thought they might be helpful to someone out there:

  1. Planning is sometimes not such a bad thing
  2. Working with two or three major characters is much easier than six or seven
  3. It’s okay to kill people off
  4. Stick with a concept – don’t write to write to whatever comes to mind
  5. Write where and when you feel comfortable
  6. Know what you’re talking about – readers can tell when you’re faking it
  7. Yes, it’s a lot of work, otherwise everyone would do it

Having been on the other side of writing – doing technical stuff – it’s funny to see how many of these same things apply there as well. Well, okay…with the exception of a few. It’s been an interesting experience and I’m going to go as long as I can on what I’ve come up with so far (27k+ words) and I’m going to keep updating my count on the right to keep up with it. I figure that if it took me about a month to get here, I can get a lot done in December and maybe hit the 50k+ mark by the beginning of next year.

Oh, and Elizabeth, you’re not giving up either 🙂

A Shiny BlackBerry Pearl?

So I’ve been thinking about upgrading my cell phone for a little bit now (stupid tempting ads in the mail) and I’ve been looking around for something I thought would make a nice upgrade from my current flip-phone. What I really wanted was something with a bit more power so I took a look at the PDA/Smartphone category on my provider’s website. There were some nice ones on there (expensive ones too) but the one that really caught my eye was this one:

I’ve been using a BlackBerry (older model) at work and have found it pretty easy to use. The one for work is a bit bigger and older, so the slightly smaller size of the Pearl would be nice. The only problem I’ve come across, though, is the differing opinions as to the quality of the phone and things like battery life, signal strength, etc. I’ve seen a lot of people on forums swear by them and, two threads down, people cursing them after having to exchange them four times already.

Has anyone out there had any experience with these phones? Are they worth making the upgrade to or should I just walk on by?

Some “Why Won’t Solar Work” Tips

With more and more people installing and using Solar all the time, theres some questions that get asked quite a bit. I wanted to help with some of those questions by providing some simple answers here. Here we go…

  • Tip #1 – Be sure that you have your App directory correctly set in the configuration file. If you don’t add it to your front controller Classes setting, Solar has no idea where to find it.
  • Tip #2 – Class names on the controllers are important! Be sure it follows the directory tree like Project_App_Controller. Also be sure you’re extending the right thing. I usually use a Base controller/setup to provide an overarching “global” place to put things (like a layout) and extend that, so it’s usually “extends Project_App_Base”
  • Tip #3 – You can change the values that the Solar_Form login functionality uses to trigger the automagic login process by setting it in the adapter for your authentication object (like a Solar_Auth_Adapter_Sql) via the process_login and process_logout values.
  • Tip #4 – Be sure to include everything you need to get to “magically” through Solar in the set_include_path in the front controller. For example, you can add in another directory with external libraries so that in your application, you can just call it and let the __autoload handle it.
  • Tip #5 – You might get some complaints from Solar about not having a “sql” object it can work with. I good way to handle this is to check in your _setup function of your controllers to see if there’s one registered. If not, make one with a factory call and register it for the framework’s use: Solar_Registry::set(‘sql’, Solar::factory(‘Solar_Sql’));