Posts Tagged ‘ PHP

Get Your Advent On!

Learning is so important in my industry (programming and computers in general) that you can never look at a learning opportunity as wasted time. Also it is the Christmas season, and people do Advent things… so I present the Advent list. All these sites have Advents going on that teach tips and tricks for different languages.

I hope you find these handy, and learn a thing of two!

MyGeekScore++

Ah yeah! I have finally done it! I have forked, committed, pushed, sent a pull request and now… I HAVE BEEN MERGED!

12:25 < Fuel-Bot> [oil] philsturgeon pushed 2 new commits to master: https://github.com/fuel/oil/compare/a8e1387…4be84aa                                                   eighty4
12:25 < Fuel-Bot> [oil/master] Making more use of the Form::label() in the scaffold builds – Adam Barrett                                                                    el2ro
12:25 < Fuel-Bot> [oil/master] Merge pull request #18 from utahcon/master – Phil Sturgeon

Today at 12:25MST my pull request for Oil was merged into the master line, which means it is gold!

$geekScore++;

FuelPHP: My new favorite framework

I have posted on FuelPHP once before, and I think it is time I share more about it and why I have chosen it as my PHP Framework of choice.

From FuelPHP.com:

Fuel is a simple, flexible, community driven PHP 5.3 web framework based on the best ideas of other frameworks with a fresh start.

How much clearer can they get?

The Geeks Behind FuelPHP

Dan Horrigan, Phil Sturgeon, Jelmer Schreuder and Harro Verton. If those names mean nothing to you, let me shed some light.

Dan Horrigan

Coding in PHP for 10+ years Dan has contributed to projects like CodeIgniter and PyroCMS, as well as PancakeApp.

Phil Sturgeon

Another great mind behind CodeIgniter. Just look at Phil’s blog, he has done it all!

Jelmer Schreuder

Look through Jelmer’s Github and you can see he is quite experienced as well. He is also super friend in the #fuelphp channel on Freenode.

Harro Verton aka WanWizard

After a long and sordid past as a mainframer he has found roots in programming and contributes a lot of support in #fuelphp as well. He has personally helped me through some of the beginning steps of using FuelPHP.

To all the geeks involved in FuelPHP, a huge thanks!

What Make Fuel Different?

Fuel is young, under a year as of this writing, but already it has seen support and contributions from 30+ developers. The maintainers are really open to anyone committing code cause they believe that since we all use it, we all deserve to support it. Or something like that. Basically if you use it and identify a bug, and you can fix it, then they will let you.

That is probably the best thing about this young framework is the amount of involvement everyone has. Being open source and hosted on GitHub anyone can get the source, and anyone can submit a pull request for changes to the code. I have personally been watching the commits in the IRC channel and I can attest that they are sincere in saying that things are getting done. And fast!

What Make Fuel Awesome?

Gleaming from other great frameworks (and languages) Fuel has been given some great tools. Like Oil.

Oil

Oil is a utility for the CLI that allows you to Generate code, Refine (run tasks, more on this later),  Package (install, update and remove packages) and Console (test code).

Tasks

Tasks are classes that can be run through the command line or set up as a cron job. They are generally used for background processes, timed tasks and maintenance tasks. Tasks can calls models and other classes just like controllers.

Because Tasks actually use the whole framework you can write scripts using the native language of FuelPHP and all things work. All the controllers, all the helpers etc are available to the user.

Lightweight

Autoloading is fun, and useful, but you don’t want to load everything everywhere. Fuel has an extensive (and configurable) configuration to allow you to only load what you want when you want.

Docs

The documentation is a ongoing project, and no where near perfect right now, but it certainly is coming along. Don’t take that to mean it isn’t helpful, cause it absolutely is! Also you can update the docs and commit the changes to the project ;)

ORM and Active Record or just DB

ORM has been done, and done again. FuelPHP has an ORM, or you can opt for ActiveRecord, or if you don’t like either of those you can just use good old SQL. Fuel is flexible and this is a great example of how flexible they really are.

Why Not?!

If you haven’t been sold by my simple blog post on Fuel, then perhaps you need to play with the framework yourself. You can get it from http://fuelphp.com or  from GitHub.

What’s Next?

I am working on a series of blog posts showing how to do things with FuelPHP, so keep tuned for those.

State of Zend Framework 2.0

Matthew Weier O’Phinney has posted about the State of Zend Framework 2.0:

The past few months have kept myself and my team quite busy, as we’ve turned our attentions from maintenance of the Zend Framework 1.X series to Zend Framework 2.0. I’ve been fielding questions regularly about ZF2 lately, and felt it was time to talk about the roadmap for ZF2, what we’ve done so far, and how the community can help.

He goes on to talk about the processes being taken to get Zf2.0 the exemplar of PHP 5.3 and to add namespaces to the project. He talks about his team, the road map and the struggles they have already expereienced:

After completing this process, my entire team — all three of us — started the work of migrating the code to namespaces. Ralph wrote a tool that scanned the library and created a map file of existing classes and suggested namespace/classname combinations. We then used this tool as a launching point for the migration, each of us working on a component at a time. This work was by no means automated — we discovered very quickly that such a tool only took care of the most cursory work. I detailed some of our findings a couple months back; we ran into a number of issues we never anticipated, and the progress has been far from speedy. At this point, however, we have migrated everything but theZend_Service classes, the MVC, and those components that build on top of the MVC (Application, Navigation, Form, etc.).

Finally he shares details about getting ZF2.0 available through Git and Github, and what the community can do to help:

A number of contributors are also starting to discuss rewrites and refactoring of components. Much of this is being done on the zf-contributors mailing list, and some on the #zftalk.dev channel on Freenode. If you are interested in contributing, I highly recommend subscribing to the list and dropping into the channel when you can.

You can read the post in it’s entirety at  http://weierophinney.net

PHP, Soap and WSDL Caching

Today I was offered a free lesson in how PHP handles Soap, and more specifically WSDL caching.

When you instantiate a PHP Soap Class you pass it a WSDL (Web Services Description Language) and it looks like this:


$client = new SoapClient('http://example.com/services/thescript.php?wsdl');

Depending on how your caching is setup, this will go out to the WSDL provided, pull in the document and store it in a cache. The default cache for PHP is 86400 seconds. If you are familiar with time in seconds you know that that is 24 hours. So by default you only actually read the WSDL once in a 24 hour period. Normally this is not a problem.

What is a WSDL?

For that answer let’s turn to the W3 site:

WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information.

So in English that means it is a map to the services provided by the provider. Basically you get a copy of the map, and follow the endpoints to the answers you need.

One basic function of this is that it tells you want methods (services) are available on your fresh client.

When WSDLs go bad

So today one of my providers, without warning, updated their WSDL. This wreaked havoc on my system because I had cached the WSDL on my side for 24 hours (remember, the PHP default). The change was a super simple change, a change in URL for a service, that’s it!

The problem was that since PHP had already read the file within 24 hours it didn’t care that there was a new file, that the URLs had changed, and so it continued to work as it had before.

The real problem wasn’t that the URLs changed, that would have been fine if the provider hadn’t shut off the previously reported URLs.

Turn off the cache

So you are left with two options when something like this happens. First, you can sit and wait up to 24 hours for the problem to fix itself. This was not an option for us. The second is to clear your cache and try again.

Now PHP (on Linux) stores the cache for the Soap WSDL in /tmp and I wasn’t sure which one of the many files was the actual cache for this particular provider so I decided I would have to tell PHP to not cache the WSDL and try again.

Into php.ini I went, located the soap.wsdl_cache_enabled flag. I changed it from 0 to 1


soap.wsdl_cache_enabled=0

I saved the file and restarted Apache.

The service continued to fail. I was perplexed. I thought maybe I flubbed the save so I opened the php.ini again located my line and it was fine. So I looked around there to see if maybe I missed another important flag. The only thing I could find was soap.wsdl_cache_ttl listed as the “(time to live) Sets the number of second while cached file will be used instead of original one” I promptly changed this to 0 as well


soap.wsdl_cache_ttl=0

Restarted Apache, and finally my script stopped failing.

I have since re-enabled my cache ttl and enabled flags, as reading the WSDL every time is a resource hog that doesn’t need to be in place.

The Lesson Learned

The lesson learned by all today is be aware of your caching, and be aware of the changes you make to your live/production systems.

Matt announces WordPress Foundation is Live

It looks like Matt and company have been busy getting things lined up for the WordPress Foundation, a non-profit with the goal:

“to ensure free access, in perpetuity, to the projects we support”

From the About page:

The WordPress Foundation is a charitable organization founded by Matt Mullenweg to further the mission of the WordPress open source project: to democratize publishing through Open Source, GPL software.

The point of the foundation is to ensure free access, in perpetuity, to the projects we support. People and businesses may come and go, so it is important to ensure that the source code for these projects will survive beyond the current contributor base, that we may create a stable platform for web publishing for generations to come. As part of this mission, the Foundation will be responsible for protecting the WordPress, WordCamp, and related trademarks. A 501(c)3 non-profit organization, the WordPress Foundation will also pursue a charter to educate the public about WordPress and related open source software.

I have long been a fan of WordPress, and now even more so. I am always amazed at the things that Matt and company come up with to move forward the power of WordPress.

For all those true WordPress geeks out there, the new site is running the WordPress 3.0 development version.

PHP and Josso – Transparency Rocks!

Bogdan recently asked in my comments:

I can’t seem to find a call like josso_authenticate($name, $pass), returning an array to be appended to user’s SESSION. I was expecting such a method, because SOAP is already used everywhere, so it shouldn’t be too hard implementing this.

Has anyone had success implementing this kind of “transparent” login?

JOSSO simply doesn’t make it easy to log people in with a single call. Instead you need to make an interface to the API to do so. I just so happen to have an example of such a wrapper function.

Read more

Let’s Get Open!

Being that it is Monday and I am really not feeling it today I thought I would dig up what is happening around the nets and share with you.

Chrome OS Zero

Looks like Hexxeh has been hard at work getting a cleaned up version of Chrome OS called Chrome OS Zero out to the masses. Reading through the Wiki and FAQ things look pretty nice and clean. I may take a stab at playing with this in the next week or so. Thanks Hexxeh!

Droids

Tim at CTRL-ALT-DEL Comic has this silly for us today:

Thanks Tim!

Nexus One

We all know about Google’s latest move in the Android field by now, right? Well it looks like the Nexus One is selling well, and people are having problems with the 3G service that T-mobile is offering on the Nexus One. Being a T-mobile customer myself I can tell you the problems are not limited to the Nexus One. My phone refused to stay on 3G this weekend too, oh well.

PHP

References

Johannes Schluter discusses how references in PHP work, and suggests that maybe we should not use them anymore.

Last year I spoke at eight conferences and attended a few more multiple times at most of them I found myself in discussions about references and PHP as many users seem to have wrong understandings about them. Before going to deep into the subject let’s start with a quick reminder what references are and clear some confusion about objects which are “passed by reference.”

Patterns

Giorgio Sironi has two new blog posts about patterns in PHP. The first is on Abstract Factory patterns:

The major problem that creational patterns try to solve is that objects need collaborators: we often pass them in the constructor of a Client class to aid decoupling, as every class should know only what it really needs to get its job done. With the verb know I mean that they just know that the other part exist at all.

The second is on Builder patterns:

The Builder pattern’s intent is to encapsulate the details (the new operators and other wiring) of the object creation process under a common interface. Though, the Builder can actually change the internal representation of an object, as it is not a black box.

Both blog posts were great reads, and I suggest all my UPHPU buddies hit them up.

Pro PHP: Patterns, Frameworks, Testing and More

Pro PHP: Patterns, Frameworks, Testing and More

Pro PHP: Patterns, Frameworks, Testing and More

Kevin McArthur is a self-taught entreperneur and opensource developer from Edmonton Alberta. Kevin has been running a very successful PHP application development studio for over 7 years. Additionally Kevin took time to write Pro PHP: Patterns, Frameworks, Testing and More, published by Apress.

The book really lives up to the name. It disucsses in great details the framworks that are most popular including Zend Framework. Kevin has what seems an infinite amount of knowledge on Zend Framework, and a quick Google search will reveal he is quite active is sharing that information.

I was a little let down on the Testing and Code Control sections of the book. I felt like Kevin mearly skimmed, and could have really dug into more detail, espeically about testing.

In talking about patterns for PHP Kevin reinforces some of the basics of good programming, and explains the pros and cons of each style of framework. You can tell he has spent his fair share of time in each of the patterns discussed.

Overall if you are thinking about playing with patterns and frameworks this is the book for you. Don’t look for any golden knowledge about testing, but the rest is gold!

Book Review: RESTful PHP (Packt Publishing)

This weekend I had the opportunity to read RESTful PHP, by Samisa Abeysinghe, published by Packt Publishing. The book is short, about 200 pages, but full of great information about what REST is, how it is used, how it is supposed to be used and how to use it with PHP.

The book assumes you have a working knowledge of PHP, and how to install extensions (or use existing ones). The concepts are clear and concise. Samisa is direct, but explains the reasons for why code is the way it is, or explains what can be done different.

The books runs through many examples using Yahoo! and Amazon APIs. Most of the book could be called a manual for use of CURL and SimpleXML, as well as some DOM work. Although you will not need to know any of those things before picking up this book.

In a short seven chapters Samisa explains what rest is, who uses it, why it is used, and what you can do with it. Samisa walks you through consuming (or using) REST APIs and also how to setup your own APIs using the REST style and architecture.

I would recommend this book to any beginning and middle tiers PHP developer as it is a quick reference to REST and APIs that you know you already want to be working with.