Archive for the ‘PHP’ category

Is your project scalable?

August 17th, 2010

I was talking with a friend today about his project.  He’s been brought in to a project where the dev environment is pretty tightly couple with physical machines, there’s no good repeatable build process or docs on how to make things work, and many unwritten assumptions that he only finds out after trial and (much) error.

It struck me then (and possibly in the past) that the entire way that project is set up is not *scalable*.  Scalability is a big buzzword, and it often focuses on performance.  While faster performance is generally a good goal, it’s often not the only requirement on a project.  In the case above, a new developer coming in may spend *weeks* trying to get things working which should only take hours.  And the process of getting him up to speed is not a documented, repeatable process either.  So when he leaves, and they bring in someone else, they’ll go through the same process all over again, probably not even realizing there’s a problem.

What steps do you take to ensure your project (or perhaps your project team) is itself scalable with respect to the human resources it requires?

Web freelancer conference

July 21st, 2010

indieconf – the conference for independent web professionals – is now open for registation.

What is indieconf? It’s a conference that brings together the topics that affect freelance web people with experts who’ve been there and done that.  I’ve attended a number of tech/web conferences over the past 12 years or so, and while they’ve all been ‘good’, there’s usually very little in the way of information that helps me in the business side of my work.  As an independent, there’s questions about bookkeeping, outsourcing, legal issues, time management, billing, sales and marketing, and more that don’t typically get addressed at the typical tech conference.  And at ‘small business’ events (conferences, networking meetings, etc), there tend to be very few ‘web geeks’ who speak my own language and understand the particular challenges that I face.

So, from that quandary, indieconf was born.

I’ve been contemplating this for a while, focused the idea some, and have been working for the past 6 weeks organizing a core set of speakers/sessions, location, paperwork, and more ‘stuff’ that goes on with a conference.  I’m not even half done, but have been having a great time so far.  I think we’ve got a pretty solid line up of speakers and sessions so far, although we’ve got room for a few more (planning between 15 and 18, and we’ve got about 9 or 10 nailed down).

One of the things I’ve tried to do with this is to get speakers from outside the Raleigh area.  Right now we’ve got speakers from California, Texas and Pennsylvania as well as the Raleigh area and the Carolina coast.  Even people who’ve been to many local or regional events in the NC area likely won’t have crossed paths with all of these speakers, which I hope is seen as a good thing (I think it is!).

So whether you’re a PHP guru just starting out freelancing, a PSD master who’s been at it for years, or someone just considering getting in to the world of freelance web work, I think indieconf will have something for you.  With that said, what are some other types of sessions/info you’d like to get out of a conference like this?  I’ve got some more topics planned based on early feedback from people, and would like to take on a bit more before making more decisions.

I look forward to seeing you in Raleigh this November at indieconf!

twilioKit php starter kit

June 19th, 2010

I’ve adapted my ZFKit for an upcoming Twilio presentation (codestock next weekend!) and created a new project on github for it under the project name ‘twiliokit‘.  ZFKit was updated a little bit (a basic menu/navigation was added with Zend_Navigation, some example unit tests added) and used as the basis for this.

You can see this in action if you want to play around with it a bit.

I’ve modified the twilio REST client available from Twilio.com.  While functional, it wasn’t the easiest thing to use, and I’ve added a couple helper methods which may make things a bit easier for people.

I’ve got two examples so far – one is a basic ‘send SMS message to a phone’ controller, which uses my new helper methods in the Twilio_Rest_Client library.  The second is a small guessing game which demonstrates making use of ZF sessions.  You enter a phone number (and name!) to call, and the app will call up and ask the person to add two numbers together (“hello dave.  What is 4 + 2?”)  Based on your answer provided, you’re told whether you were correct or not, then offered a chance to play again.

I should have a few more examples before next weekend, but there’s actually quite a bit going on, between the ZF code and the Twilio code.  I’m working on something (in the code now) which will log all the call activity, and I’m working on it logging everything to a Doctrine table.

When you first use twiliokit, you’ll need to enter the ‘scripts’ directory and run the ./run script.  This will create the necessary ‘tcall’ table to store the info.  This is building from a schema.yml file to a local sqlite file.  You will probably need to chmod 777 the dev.db sqlite file, depending on your system’s permissions.

Oh, and there are a couple unit tests in place in the ./tests directory (though certainly not comprehensive).

This is definitely a work in progress, but I wanted to share it on github to allow people to use it and make any changes they need and be able to easily send those changes back to me.  I was on the fence about making this just a working branch on the zfkit project, but it felt like that might get too confusing.

Let me know what you think!

Interview with Lithium developers

May 2nd, 2010

I had a quick but interesting interview with Nate Abele and Garrett Woodworth from the Lithium project.  Take a listen over at webdevradio.   Subscribe to the podcast series via iTunes or RSS to hear more in the future.

Zend Framework starter kit interest?

March 30th, 2010

I’m putting together a basic Zend Framework starter kit.  Right now I’ve got basic Doctrine 1.2 integration with predefined directories for schema, models, etc.  Also an init process to allow for automatic injection of specified objects on to front controllers (think $this->session available in your controllers, for example).

Any interest in getting a copy of this?  What other things would you like to see preconfigured or preintegrated in a starter kit?

Zend Framework and Doctrine integration – autoloading of doctrine models

March 3rd, 2010

I’m reinvestigating Doctrine and Zend Framework for a new project.  I’d dismissed them last year as not meeting my needs, but am giving it another go this year.  I have to say I’ve got mixed impressions at best, as there seems to be little in the way of documentation with real use cases.

I would have expected there to be some explicit reference to how to set this up, but the best I can find are general examples where the Doctrine models directories are appended to the include_path in a ZF index file.  Shouldn’t there be a way to explicitly have the Doctrine subsystem react to requests for models as well?

I was expecting the Doctrine::autoload to look for the classes on the ‘models path’ set via Doctrine::setModelsDirectory() call, but it doesn’t.

Hrm… after more investigation, it seems there’s a ‘modelsAutoload’ method on the Doctrine_core which will automatically look at the models_path set via setModelsDirectory().  Almost what I need.  Except…(!)

There’s no support for multiple directories.  The standard Doctrine generation process creates a ‘BaseFoo’ object in a ‘generated’ directory below where the standard ‘Foo’ file is written.  The ‘Foo’ file subclasses the BaseFoo, but there’s no support to have it autoloaded.

In my ‘_initDoctrine()’ in Bootstrap, I’ve got

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->pushAutoloader(array('Doctrine','modelsAutoload'));

I know what to do here! I thought to myself. I’ll subclass Doctrine’s Core (which is what’s referenced by the ‘Doctrine’ above) and have that be the autoloader to use.  I’ll modify the modelsAutoload() method to deal with an array of $_modelsDirectory entries, and attempt to load from each of them.  Except…(!)

$_modelsDirectory is *private*.  I can’t modify it in a subclass, nor is there a get() method on the Core class to access it.  There’s a *set* method (setModelsDirectory()) but no get!  So, I’m rather forced to go through modifying the Doctrine Core to get the behaviour I want, in the simplest form.  I’ve been trying to followup on some other postings about getting autoload to work with Doctrine-generated models, but they seem incomplete (to me anyway) or suggest to modify how Doctrine generates its class names (doesn’t seem simple or straightforward to me at all).  Having Doctrine core be able to deal with an array of paths to check for models would be the simplest, especially given that Doctrine *forces* this issue on you by generating classes in different directories by default.

Crux of the code is:

Doctrine/Core.php line 1142

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if(is_array(self::$_modelsDirectory)) {
 foreach(self::$_modelsDirectory as $dir) {
  $class = $dir . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
  if (file_exists($class)) {
   require $class;
   return true;
  }
 }
} else {
 $class = self::$_modelsDirectory . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
 if (file_exists($class)) {
  require $class;
  return true;
 }
}

I don’t see Doctrine code on github – if it’s there I’ll fork it and create my own patched version for a pull.

So now in my code, I can say

Doctrine::setModelsDirectory(array("/app/doctrine/models/","/app/doctrine/models/generated/"));

FWIW, I can’t find the equivalent code section in Doctrine 2.0, though I suspect this might still be a design issue in 2.0 (would love to be proved wrong on that).

How have *you* dealt with autoloading of Doctrine-generated classes in ZF (or indeed, in general)?

Next magazine topic survey – winner announced

December 23rd, 2009

A few weeks ago, I posted a survey asking for input on the next magazine topic for Web Dev Publishing to pursue.  The results were interesting, but unfortunately the results were not definitive, and I’m left with the same quandry as before – which topic to choose.

The winner of the survey, selected at random, was Mark McDonnell.  Congrats Mark, I’ll be sending your Amazon Gift Card over today.

The top vote getters were (in no particular order)

  • MySQL
  • NoSQL
  • JVM Languages (jruby, jython, scala, clojure, etc)
  • Zend Framework
  • Database technologies

The votes were pretty evenly split between all of these topics, which leaves me with no clear direction as to which, if any, of these topics would make sense to pursue (from a demand standpoint).   There already was a MySQL PDF magazine, which has transitioned in to a “open source database magazine”, covering more technologies than just MySQL.  NoSQL, while interesting, has been criticized as just a ‘flavor of the month’ (though the interest shown in this survey was significant).  Zend Framework and JVM Languages are the two that seem the most promising.

Do you have any thoughts on this?

Learning new languages harmful?

December 22nd, 2009

After having spent much time with Groovy/Java, and a bit with Ruby and a bit with C#, I have a newer perspective on learning new programming languages.  Much of my thoughts are summed up by this post from Gustavo Duartes.  I liked his choice of words at the top – “language dabbling” – which largely describes my C# and Ruby experience.  I’ve done a little bit in them – some paid in C#, some not – but the bulk of my work is in PHP, with a small but growing bit in Grails.

It’s interesting to note his acceptance of “more than one”, but focusing on the “minimal required set”.  We tend to think of languages as Java,C#, Python, etc., but competent web developers need to have a handle on SQL and JavaScript as well.  Many also get into Flash/Flex/Silverlight too, and while CSS isn’t a *language* specifically, it’s something most web developers should be acquainted with.  So, regardless of your serverside language of choice, there’s going to be 2-4 other technologies you need to be at least competent, if not proficient, with.  This may be more the realm of small shop and independent developers – people working on larger teams or in companies with divided responsibilities may be able to get away without knowing any SQL or JavaScript, for example.

One of Gustavo’s points was that you lose momentum on your main language when you start dabbling with others.  There may be a point there, but I suspect some people end up looking at other languages when they reach a plateau in one.  That was certainly my point I reached with PHP.  Having used it since early 1996, there’s only so much more I feel I can do with it.  Yes, the language is evolving slowly, and I’m not keeping up with the ‘best practices’ of namespacing and such in 5.3, and I could probably architect my apps somewhat more strictly using some of the bigger frameworks out there.  However, one of the things you end up learning when you look at other languages is where some of the defects are in your primary language.  You may start to see the new ‘best practices’ as work-arounds in language deficiencies.

It’s easy to point at PHP and talk about how “it sucks” and all that, but I’ve had experiences with some friends who’ve moved from Java over to PHP.  While this was a somewhat unwelcome move at first, given PHP’s reputation amongst the ‘enterprise crowd’, at least one of my friends is really enjoying being able to be much more productive – more functionality in fewer lines of code – and rethinking some of his approaches to web development.  Moving from any statically typed language to a dynamic one is certainly a shift for people to make (and the reverse movement is true as well!), and rethinking those problems we’ve taken for granted can be a real eye-opener.

In the short term, yes, it’s a productivity loss, as Gustavo points out.  In the longer term, it can really provide you with many more tools in your toolkit for attacking new problems.

One caveat I’ve noticed to this is the old saying “choose the right tool for the job.”.  Great in spirit, but my experiences have borne out that rarely is the definition of “right” able to be agreed on.  ”Right” for who?  The DBA?  The sysadmin?  The developers?  I had a project I’d recently prototyped in Grails (after an initial first pass prototype in PHP 6 months earlier).  The Grails environment allowed for much more rapid prototyping and modeling of data, relationships, screens, and so forth.  However, when it came time to accept it, I was told we could *only* build the app on a traditional LAMP stack (I was looking forward to using PostgreSQL on this project as well).  Why?  Because the limited system administration staff didn’t have the time to learn new skills to manage the new technology choices.

While initially I was bummed out, I can understand the decision making process.  I was able to take the db tables from Grails and wrap another PHP ORM layer around them so I didn’t lose all my work, but it certainly put to rest the maxim “right tool for the job.”  Who gets to decide?

So, even if you learn new languages and technology, you might not always be able to use the most appropriate tool from a pure technology/productivity standpoint.  And sometimes knowing that there are better options out there that you *can’t* use for various reasons adds a level of frustration to the mix that you wouldn’t have.  Perhaps we should all stick to just knowing one language and one language only, right?  :)

Next magazine topic survey – enter to win

November 24th, 2009

I’m turning to the community to help determine what our next magazine topic should be.  Please visit http://webdevpub.com/topics to give your input on what you’d be interested in reading more about.  Entrants who submit an email address will be entered to win an Amazon gift card, to drawn on our around December 9.

PHP On Windows – presentation slides

September 19th, 2009

I gave a talk today at the Raleigh Code Camp titled “PHP On Windows”.  It was decently attended, given the attendee focus at a Microsoft-sponsored event.  MS has been embracing PHP much more publicly over the last year or so, and I reviewed some of the steps they’ve been taking (auto-install on IIS7, recent bytecode cache from MS, etc). The slides I used were relatively sparse, as some of the presentation was simply doing some code on Windows.

I will probably expand on this talk and may give it again at some point.  If you have any good resources or info about PHP on Windows, let me know.