2010-09-03(金)
アイディアまたはご教授ください。
Error handling was optimized for initializing IMAP connections.
Fixes were applied to unicode names in the WebDAV server and uninstalling extensions.
Gonzalo Ayuso takes his "CouchDb as a filesystem" approach one step further (see the previous post about it here) with this new post talking about monkey patching to store files into the CouchDb server using the normal PHP file handling functions.
Since PHP5.3 a new design pattern is available for us: Monkey Patching. With this pattern we can override PHP's core functions with a home-made functions in a different namespace (another example here). That's means if I have fopen function in the above example, PHP uses the filesystem function "fopen" but if we set a namespace in our example, PHP will search first the function within the current namespace.
By defining the new interface inside of a namespace (with functions to override the default PHP file handlers) you can have the rest of the code call the same functions (fopen, fread, etc) but they'll do different things. In this case it handles them as push and pull to the CouchDb instead of the normal filesystem. You can grab the source for this example here.
Kevin Schroeder has another new post to his blog today with an excerpt from his "You Want to Do WHAT with PHP?" book. This new post is a section from the fourth chapter looking at stream handling.
Communication is key to building applications now and for the future. While it is not something that I think that everyone should do, I have not seem many applications that make good use of streams in PHP. Streams can be immensely useful in the right situations, but a lot of developers are not really aware of how streams can be used. [...] While I don't think you will end up basing your application around streams it is a really good idea to know how streams work.
The sample code (and description) talk about changing the properties of a stream on the fly. He shows how, with a fgets loop checking the input, he can catch a command from the already running script and change the compression setting on the currently open stream. The compression changes the stream's data from plain text to a binary format as handled by the streams functionality.
On the TechTatva.com site today there's a new tutorial posted about getting the Cherokee web server set up and running PHP5 FPM. It's a few simple steps to install and a few clicks around the GUI to get things configured.
In this "how to" we will see how to setup cherokee on Ubuntu with PHP5-FPM (FastCGI Process Manager). Although the cherokee CookBook claims that "If PHP-fpm binaries are found, those will be prioritized over the regular binaries." it turns out that the latest stable version of cherokee in Launchpad gives errors while enabling
A few calls to "apt-get" install some packages (Cherokee and php5-fpm) and changes to the Cherokee configuration - handled through its web-based interface - are all that's needed to add a new behavior rule to the default vServer to link to the PHP5-FPM install (as FastCGI).
According to this new post on the Zend Developer Zone, the Zend Framework has won itself a BOSSie award (from InfoWorld) in the "best open source application development software" category. Matthew Weier O'Phinney has this to say about the award:
I am one of the privileged few to have worked with Zend Framework since before the original public pre-alpha release. [...] What [Mike Naberenzy] showed me at the time captured my imagination: the company with the best known name in the PHP industry was building an application framework, and the code I was seeing was simple, straight-forward PHP. It was the first time I'd seen a framework I was actually interested in using -- even if it was in its early, early infancy. I knew at that moment that I wanted to be involved in the project.
He mentions some of the things that "shook up" the development world when those first versions of the Zend Framework came out - like the PHP5 requirement and the CLA you had to sign to contribute.
Other BOSSie award winners include jQuery, Apache Hadoop, Git and Go.
On the ThinkPHP blog today there's this new post talking about open source contribution and, more specifically, making contributions to a popular PHP project - the Zend Framework.
Who hasn't ever started writing his own Framework/CMS? It is considered best practice for learning purposes, but going through all the security stuff can be stressful and boring at the same time. That's where most devs start to contribute to big Open Source-projects like Typo3 or the Zend Framework, because they are already experienced working with it and yet evolving another system on the market or even getting people to contribute seems like an unachievable task.
They talk about the evangelizing that all of the Zend Framework tutorial posts do to further the cause of ZF use and how they can help introduce beginners to the framework even easier than them trying to submit bugfixes right from the start. They also talk about the process of contributing back to the Zend Framework - signing a CLA, reading the standards, grabbing the code from the subversion server and checking out the bug tracker for things to get in and fix (and write unit tests for, of course).
2010-09-02(木)
On Developer.com today there's a new article talking about memcache and how you can implement it in your application to provide a performance boost for applications in a distributed environment.
As distributed system is part of the Memcached definition, you can install Memcached on various servers to make a larger caching server. In this way, Memcached helps reduce database loads to a minimum, resulting in faster and more responsive Web applications
They take some time to explain what memcache is - a simple to use caching system that reduces the dependency on other data sources - and how to get it installed (via the package manager of your choice). They suggest times on when and when not to use it as well as some of the security implications you'll need to worry about when implementing it. There's also a bit of sample code to help you get started in your application. You'll need the memcached extension to make it all work, though.
Jos Poortvliet did an interview with me for dot KDE in this summer's aKademy and it has been online for a while now. In it we discuss things like Midgard as a storage engine for desktop applications, and Maemo's open QA process for Downloads applications. Some excepts:
At maemo.org we have an appstore for FOSS applications on the Maemo platform. This appstore is enabled by default on all Nokia N900s so we wanted to have some quality control. We had to create our own appstore approval process, compatible with the FOSS philosophy. Now any developer can submit an app, and anyone can test and vote. The whole process is completely transparent, auditable and visible. And it also provides a feedback channel from testers and users to the developers!
...
Midgard is a data storage service. Whether you write desktop or web applications, instead of coming up with your own file format, you just use Midgard. You can work more easily and object-based. Users have many different devices these days, so Midgard has strong replication features to synchronize between different systems. Midgard is built on top of GObject; we provide bindings to a bunch of different languages so developers can choose the tools they like - PHP, Python, Javascript. Currently (as in now, while we're talking) Qt bindings are being developed here at Akademy.
On the AjaxRay.com site today there's a new tutorial for the Zend Framework users out there with a library they can use to extend Zend_Form for custom phone number fields.
When taking Phone number as user input, we can worn users about phone number format by setting a hint/description and can validate using Regular Expression. [...] Now, if we try provide this feature in Zend Form, that's possible. We can create three individual Zend_Form_Element_Text objects and join there value together to make the phone number. But, in this case, validating them together is a hassle.
Instead of separate fields, the library they create makes it simple to handle them as a whole field. It works as a helper for Zend_Form and lets you set things like the separator between the text fields, a "format" string and a validator to apply to their fields (in the example code, it's the "digits" validator). Sample code is included to show you how it fits in your form.
- Community News: PHP Cache Accelerator for Windows
- Joomla Blogger: Update: Joomla 1.6 Release Plan
- Developer.com: Build your own MVC Framework: Making Headway
- Lorenzo Alberton's Blog: Create a video preview as animated GIF with FFmpeg and PHP SPL
- David Kent Norman's Blog: Drupal on Snow Leopard
- Davey Shafik's Blog: Fixing ZDE 5.5 on Snow Leopard (Crashing & Text Selection Bugs)
- Web Development Blog: Sending e-mails via SMTP with PHPmailer and Gmail
- NETTUTS.com: CodeIgniter From Scratch: Day 5 '" CRUD
- Blue Parabola Blog: Magento Feature Analysis Series, Part 7: Order Management Offering
- Samuel Folkes' Blog: Where Has All The PHP Gone?
- Daniel Krook's Blog: Technology of the day: Zend Server
- The Bakery: Clearing Up Some Confusion on the Release Versions of CakePHP
- Benjamin Eberlei's Blog: Enums in PHP
- Dagfinn Reiersol's Blog: Don't refactor without unit tests
- DevShed: Sanitizing Strings with Filters in PHP 5
Packt launches fifth annual Open Source Awards
The 2010 Open Source Awards was launched last month by Packt, inviting people to visit www.PacktPub.com and submit nominations for their favorite Open Source project. Now in its fifth year, the Award has been adapted from the established Open Source CMS Award with the wider aim of encouraging, supporting, recognizing and rewarding all Open Source projects.
WordPress won the 2009 Open Source Content Management System (CMS) Award in what was a very close contest with MODx and SilverStripe. While MODx was the first runner up, SilverStripe, a Most Promising CMS Award winner in 2008, made its way to the second runner up position in its first year in the Open Source CMS Award final.
The 2010 Award will feature a prize fund of $24,000 with several new categories introduced. While the Open Source CMS Award category will continue to recognize the best content management system, Packt is introducing categories for the Most Promising Open Source Project, Open Source E-Commerce Applications, Open Source JavaScript Libraries and Open Source Graphics Software. CMSes that won the Overall CMS Award in previous years will continue to compete against one another in the Hall of Fame CMS category.
These new categories will ensure that the Open Source Awards is the ultimate platform to recognise excellence within the community while supporting projects both new and old. “We believe that the adaption of the Award and the new categories will provide a new level of accessibility, with the Award recognizing a wider range of Open Source projects; both previous winners while at the same time, encouraging new projects” said Julian Copes, organizer of this year’s Awards.
Packt has opened up nominations for people to submit their favorite Open Source projects for each category at http://www.PacktPub.com/open-source-awards-home . The top five in each category will go through to the final, which begins in the last week of September. For more information on the categories, please visit Packt’s website http://www.PacktPub.com/blog/packt’s-2010-open-source-awards-announcement
It can take a limit number and find all prime numbers smaller than the given limit.
It can send HTTP request to the Guitar chord API Web server to find chord variations based on given data about chord by specifying the chord name, chord modification, or/and string/fret combination.
In a new post to his blog Gonzalo Ayuso shows an interesting use for the CouchDB tool - using it as a filesystem for cross-server handling of things like images or other binary resources.
One of the problems I need to solve in my clustered PHP applications is where to store files. When I say files I'm not speaking about source code. I'm speaking about additional data files, such as download-able pdfs, logs, etc. Those files must be on every node of the cluster. [...] CouchDb has two great features to meet or requirements with this problem. It allows us to store files as attachments and it also allows to perform a great and very easy multi-master replica system.
He shows how use two libraries he's created to connect to the CouchDB instance and, based on this structure, be able to insert the content - a text file in this case - pull it back out, get the meta data about it and even move it to another location in the structure.
On the Web Builder Zone (from DZone) Giorgio Sironi has posted a new article that talks about the different kinds of testing you can do on your application - both on the frontend and backend.
Automated testing supports your constant effort in design and refactoring, and besides that ensures that your application actually works in a reliable and repeatable way. [...] In this article I'll describe the different categories of testing, as applied to a Zend Framework 1 application, but this classification pertains to every web application based on object-oriented programming. Since this kind of applications is obviously PHP-based, PHPUnit will be the tool of choice along with some of its standard extensions.
He looks at five different types of testing you can do on your application:
- Unit testing
- Pragmatic unit testing
- Functional testing
- Integration testing
- Acceptance testing
Not all of these can be done with PHPUnit on the backend, but they (mostly) have automated tools of their own like Selenium for frontend interface testing.
Josh Holmes, just coming off of presenting at OpenCa.mp in Dallas, has posted his entire presentation to his blog for anyone that missed it and wants to catch up. He spoke about scaling WordPress on the Windows platform. He also includes a lot of content in the post that he wasn't able to get to during the presentation.
Now, on to my session itself. This was a fun session. I only had 30 minutes and I had about 3 hours of material so I've got a ton of stuff in these notes that I didn't cover in the session itself. The session is a take off a session that I did at MODxpo back in the spring. The talk itself is about 3-5 minutes of slides and the rest is all demos.
If you're looking for the actual slides, they're over on slideshare, but the real content - including the demos (and screenshots of them) are included. He talks about the Windows Platform Installer, the WinCache library and Windows Azure Data Storage.
I’m excited to announce I’ll be speaking at PHPNW Conference, to be held October 9th, 2010 in Manchester, UK. I’ll be doing my talk, “Developing Easily Deployable PHP Applications“, which I also did in July at OSCON. I’m working on making the talk even better based upon feedback I received, and will talk more about the various tools we use and have developed to make building SugarCRM easier.
This is my first time to this conference, but judging from the lineup of talks it is not one to miss if you are in the area. The lineup has several exciting talks about PHP development from some of the biggest names in PHP. You can register now at the conference website; early bird registration ends on September 4th.
2010-09-01(水)
New on PHPBuilder.com today there's a tutorial showing you how to download and parse messages from Google Mail. In their case it's grabbing and parsing submissions from a form.
Some friends of mine publish a literary journal that accepts submissions via email. At their request I wrote a script to download messages from the journal's Gmail account and do some simple parsing tasks. Most of the submissions are made using an HTML form and a corresponding mailer script on their website, so I knew the precise format of the incoming messages (see Figure 1). What I didn't know was how to access Gmail in PHP.
He tried out the libgmailer script first, but ran into roadblocks until he realized he could use something PHP already had - the imap functions. With these he shows how to make a connection to the Gmail servers, get the listing of messages and pull out the body for the one you want to parse.
On the Zend Developer Zone today there's the first part of a series from Vic Cherubini about an ORM tool he's created to make pulling data from your database of choice (via PDO objects) simpler - DataModler. This first part looks at creating testable models.
DataModeler allows you to create easily testable Models that are not dependent on any datasource. The majority of your logic should take place in the Model, and not the Controller (making your application even easier to test as data sources can be mocked). I try to keep my code as simple as possible, so DataModeler is fairly small.
He talks about how the DataModler tool uses dependency injection and how one primary namespace (DataModlerModel) contains the bulk of the code. He includes code samples showing how to create a simple mode, give the attributes data types and access them via magic "set" and "get" methods. For more information on this ORM tool, check out the latest source on github.
... on contribution
Who hasn't ever started writing his own Framework/CMS? It is considered best practice for learning purposes, but going through all the security stuff can be stressful and boring at the same time. That's where most devs start to contribute to big Open Source-projects like Typo3 or the Zend Framework, because they are already experienced working with it and yet evolving another system on the market or even getting people to contribute seems like an unachievable task. Instead of wasting his time on yet another ACL implementation, the developer is taking part in making a software become even better, no matter if he delivers new features, reports / fixes bugs or works on documentation (another, yet an often underestimated part of contribution). It is also worth noting that every single Blog-entry and every HowTo thats put on the web also is a great deal of contribution that helps the software spreading. Beginners articles are important to put on the web since every one of us had it's beginnings and these are the sort of articles where many people decide to either use the software for a certain project or not.
As you might see, this article is not only a guide on contributing bugfixes, but also I want to motivate you to just give it a try.
... on Zend Framework
Having spent almost a year at the IRC support channel, I can tell they're really fun guys to hang around with. Of course, the Framework itself developed into a great piece of software. I do not want to discuss the up or downsides of a use-at-will framework, neither I want to recommend it over {put your favourite software here}. But what I can talk about is a little summary of the support channel's chatlogs. The widely annouced channel (which is #zftalk on Freenode) includes all kinds of concerns. One kind of people finds bugs, the other do have really clever ideas on improvements, but when you ask them to contribute its all the same: they either think it takes years to get into it, the others think they might be "not good enough for this". We sure won't force or threaten people to contribute, but what I can do is taking the fear out of it and demystify the thing, so later you might see that its actually just a few minutes to spend. Let me just loose a few words to the latter ones before we get into it: You can't destroy anything, and every idea of yours can also lead to a great improvement either realted to your concern or in a completely different area. We're glad that you take your time, even if you are completely new to ZF. Some beginners concerns already caused developers to write guides and articles that are still around and are linked at times in #zftalk...
... on contributing to Zend Framework
Contributing any code to ZF requires signing the CLA, which is an agreement that both you have the right to share any code you supply, and that you will not patent that code. This is to ensure that the frameworks codebase remains business friendly, and free to use for everyone. In fact you have to actually sign a paper, having done this you can just scan and mail or fax it. This is an important step, and none of your code will be used in any official package unless you did this.
The next step will be reading the coding & subversion standards. If you already had a look at actual ZF components code you should be familiar with the standards. Once you took a short insight (you probably wont be able to just remember all of this at once), you can check out the official SVN repository. Notice, that you, even having signed the CLA and being confirmed, do not have commit rights. So you might now ask yourself how to contribute then? All magic is taking place in the bugtracker, ZF's official Jira. All bug tickets, additions and improvements are filed as tickets here. So if you find a bug, report it here, and soon there will be a discussion in the comments section of a ticket.
Mostly all of these people, being listed by their reallife names, are also to be found on different names in the support channel, so feel free to ask them any ticket-related stuff.
The code itself will be submitted as a patch file (svn diff > patchFile), and uploaded in the Jira-Ticket. This might also be done by people who do have commit rights, but one might not be sure how to fix a problem, or any question might be left. This method of code management then leaves it to the original package developer to decide whether a change should be made or it should be thought over again (might have side effects on other packages and so on).
The last yet very important point is unit tests. ZF makes heavy use of th
Truncated by Planet PHP, read more at the original (another 1916 bytes)

It takes the birth date and computes the number of years, weeks and days that the person lived.
It can register event handler callback functions that should be handled when certain events are triggered.
The main class takes requests to raise events and dispatch them by calling the registered event handler functions.
A specialized sub-class can decode JSON object parameters passed from JavaScript running on the browser to the event handler.
It takes the latitude and longitude coordinates of two points of the Earth and calculates the distance between them using the Haversine formula.
The distances may be returned in Kilometers, meters, miles, yards, feet or inches.
It takes two images and resize them to have 20 by 20 pixels to generate an array with the intensity of the color used in pixels of the resized image.
The class returns a value that evaluates the difference of the intensity of the pixels of the two images.
It can take a MySQL query and generates navigation links to browse to the different pages among which the listing of the query results will be split.
It is an enhanced version of the original package written by Marco Voegeli.
This version can also generate function for retrieving one row or all rows, serializing the object into a string, retrieve the count of row in the table. The update and delete functions were also updated.
It can traverse a given directory recursively and checks script files to see if they may contain code that may be eventually malicious.
Currently it finds script files that are using functions often used in infected scripts, such as base64_encode and base64_decode.
It can handle requests for GIF, JPEG or PNG images that need to be resized to match a certain size and need to have a watermark applied.
It can generate sets of values with different with either uniform, Gaussian or Poisson distribution.
It can also apply the generated values at an input signal in input to simulate a noise.
An additional filter class can be used to recover the original by first applying a Fast Fourier Transform, the use high-pass or low-pass before recovering the signal using the reverse Fast Fourier Transform.
It traverse a given directory recursively and search for files that have words from a list which may be read from a given file.
The class can restrict the search to files with a given file name extension and have full read and write permissions.
If you're a developer are are looking on a way to brush up on some of your "soft skills" in your career of choices, you should check out this day long camp being organized by Cal Evans - Day Camp 4 Developers.
Invest a Saturday in your career. Learn the skills you need from your five camp counselors. We promise no wallets or lanyards. This one-day, technology agnostic, online conference will feature 5 sessions in a single track. You participate in this live conference from the comfort of your own home or office. (or anywhere you have internet connectivity) In addition, you will be able to download all of the sessions after the conference for off-line review.
The event will last all day - seven hours on a Saturday - and can be accessed from anywhere you have a computer to run the GoToWebinar software. There's a cost of $35 USD for each attendee or $30 USD in groups of 10 or more. If you're interested check out the Day Camp 4 Developers site or just go on and register! You can see the schedule here.
On the Zend Developer Zone there's a new post by Vikram Vaswani about a method for creating PDF files directly from a Zend Framework application (hint: it uses Zend_Pdf).
PHP comes with a number of options to help developers dynamically generate PDF files from within their applications. The Haru and PDFlib extensions offer a complete API for dynamic PDF generation, and there also exist a number of open-source PHP components that can be used for the same purpose. This article will introduce you to one such component, the Zend_Pdf component that ships as part of the Zend Framework, and illustrate how it can be used to perform sophisticated PDF operations from within a PHP application.
The tutorial walks you through some of the introductory steps to using the component (outside of the framework) and create a sample PDF with some basic text. It gets more technical by adding in pictures, text wrapping, drawing lines and shapes, styling text and using things like the My_Pdf_Table feature to easily create tables. There's even a bit at the end about using the properties of the file to set things like title, subject and author.
Kevin Schroeder has posted another excerpt from his "You Want to Do WHAT with PHP?" book to his blog today. This time it's from the third chapter that looks at character encodings like UTF-8 or ISO-8859-1.
I realized that while this 3.5-year PHP consultant knew Unicode, UTF-8, character encodings such as ISO-8859-1 or ISO-8859-7, I didn't understand them as well as I thought I had. With that I threw this chapter in the book. Knowing about character encoding is what many developers have. Not as many truly understand it. In this chapter I try to de-mystify character encoding as a whole.
The excerpt introduces character encoding and what it really is - a translation for the computer to be able to handle the human language. The problem comes in when multiple tools try to define the same sort of letters/chatacters in different ways. He gives an example of a "hello world" string in a normal ASCII format versus one from the EBCDIC format and how it would be rendered by an ASCII-understanding browser.
On the SitePoint PHP blog today there's a quick new post showing you how to create a Javascript compressor tool with PHP that uses the Closure Compiler from Google.
In my previous post, I discussed the Closure Compiler's REST API. In this article, we'll develop a small PHP program that shows how the API can be used to compress JavaScript code whenever you need it.
He shows how to compress three "script" tags down into one that defines multiple files for the engine to grab and compress. This is passed into a PHP file that grabs the file and passes the data off to the Closure Compiler for handling (via curl). The result is then passed back and served up with a content type of "text/javascript" back to the browser.
In this new post to his blog Brian Swan talks about a tool that's been released by the IIS Team at Microsoft to make it even simpler to run multiple versions of PHP under IIS - the PHP Manager.
Not only does the PHP Manager make it a no-brainer to run different PHP versions side-by-side on IIS, it makes it easy to register PHP with IIS, configure various PHP settings, enable/disable PHP extensions, remotely manage PHP configuration via the php.ini file, and check the PHP runtime configuration and environment (i.e. see the output of phpinfo()).
Brian goes through a six step process to use this new tool to set up both PHP 5.2 and PHP 5.3 versions on an IIS server. It's as simple as installing the tool, registering new PHP versions and customizing the configurations. They'd love feedback on the tool so leave them comments here or report bugs here.
Derick Rethans is republishing an article series he wrote (originally for php|architect) about the garbage collection that is included with the PHP 5.3 releases. He kicks off the series with this first post introducing internal variable handling.
Before we start with the intricate details of PHP's new GC engine I will explain why it is actually needed. This, combined with an introduction how PHP deals with variables in general is explained in this first part of the column. The second part will cover the solution and some notes on the GC mechanism itself, and the third part covers some implications of the GC mechanism, as well as some benchmarks. But now first on to the introduction.
He introduces the concept of a "zval" - the container PHP uses internally to handle variables (along with its "is_ref" and "refcount" to tell the interpreter if it's a reference or not). He also shows how these relate to the variables you set in your applications as well as a mention of the xdebug_debug_zval function of XDebug to show how it's handled behind the scenes. He also shows how references are handled with accompanying images to show the flow. If you'd like more information on variable handling, Derick points to this article for more detail.
The new 8-core Intel Xeon 7550 processors are extremely powerful and a good platform for virtualised applications. My company is setting up PHP application running on a Xen based virtualisation on two HP Proliant DL580 for a total of 64 cores in a high availability environment. .
Why Virtualise?
First let's investigate why virtualisation is attractive. The advantages are:
- Simplified maintenance, as all software is running on virtual machines (VMs). Easy to stop and start VMs from the VM server console.
- High availability is easier to achieve, as you can just restart the VM on a secondary server if the primary server fails, assuming that the VM is stored in shared storage accessible by all servers, using shared storage methods such as NFS, iSCSI or a SAN (Storage Area Network).
- Able to optimize server hardware utilisation globally as CPUs, memory, hard disk, network resources are all shared.
The disadvantages are strangely enough related to the advantages:
- The maintenance is simplified, but the initial setup is more complex as not merely do you need to setup the hardware and the operating systems, but you have to plan out the virtual environment, such as the virtual network, and make sure that everything is properly sized as you are buying a few big machines, instead of lots of smaller servers.
- High availability means you need to invest in high quality shared storage to store the shared VMs, typically a SAN, the SAN switches and the Fibre Channel HBA cards to connect to the SAN switches.
- Need to over-configure the hardware as there is some overhead in virtualisation, particularly in terms of network I/O and storage I/O. CPU overhead for virtualisation is normally not a concern with modern virtualisation technologies such as VMWare, Xen, or Hyper-V.
In this case, our customer was comfortable with virtualisation, as they are big users of IBM AIX Logical Partitions and VMWare. Secondly, they already operate several large Storage Area Networks, and merely had to upgrade the SAN to support us. Lastly they had the budget to pay for all of this :)
VM Technology
We are using Zend Server CE (PHP 5.2), Apache 2.2 and Oracle 11gR2 running on Red Hat Linux 5.5 and Oracle VM 2.2 (which uses the Xen Hypervisor).
In the VM world, there are 4 main technologies that are popular:
- VMWare - the market leader, this company has been doing virtualisation for over 10 years and they have good products.
- Xen Based products - Xen is an open source technology that arose from some research on Hypervisors (the bare metal OS that controls all the virtual machines) done in Cambridge University. Today, several companies offer products using Xen, including Red Hat, Citrix, and Oracle. Has good support for Linux and Windows.
- KVM - many kernel hackers were dissatisfied with Xen (because the Xen Hypervisor is not Linux-based internally), resulting in the development of KVM, which is fully Linux based. KVM is not as mature as Xen, but improving really fast. Support Linux and Windows.
- Hyper-V - Microsoft's virtualisation technology. Microsoft is committed to supporting Linux also.
We chose Oracle VM (Xen) because it has good performance with Linux and Oracle databases (naturally). Oracle VM is free with optional paid support available. There are also licensing advantages to using Oracle VM with Oracle databases. Oracle database licensing dictates that if you are using virtualisation technologies such as VMWare and are purchasing CPU licenses, you still have to pay database licenses for all the CPU cores of the server, even if the database VM is using only 1 core. However if you are using Oracle VM, then you only have to pay for the CPU cores you use using; this is known as "hard-partition" licensing in Oracle terminology.
I also have experience with VMWare, and can recommend it as an mature alternative. Apparently the Citrix Xen Server is a good product, but I don't have experience with it.
I will cover more technical details in part 2, which i will be writing in September after I complete this installation.
2010-08-31(火)
Ilia Alshanetsky has a suggestion for those setting up PHP and Apache2 for the first time - beware of the default configuration!
About a week ago, I was doing some upgrades on my development machine and came across a rather nasty issue when it comes to how .php(s) files are associated with PHP in Apache. It seems that a number of distros including Gentoo (which is what I was using) are using the [same] configuration directive to make the PHP module parse PHP files
The problem comes from their use of "AddHandler" versus "AddType" when telling Apache which files to parse as PHP. The first allows anything with ".php" in its filename to be parsed while the second limits it to just files ending in ".php". Check your configuration to ensure you're not open to this issue, especially if there's scripts/files outside of your control.
Wouter Lagerweij has posted a list of books he thinks every programmer should read to help them get a better handle on their process overall (they apply to any language out there, really).
When discussing books on software engineering with colleagues, I got the idea of listing the best books I've read in the past 15 years. Because it seems useful, but also because that will allow others to tell me which ones I should have read.
He lists five books that cover some of the "meta" about programming:
Collecting Garbage: PHP's take on variables
This is the first part of three-parts column that was originally published in the April 2009 issues of php|architect.
In this three part column I will explain the merits of the new Garbage Collection (also known as GC) mechanism that is part of PHP 5.3. Before we start with the intricate details of PHP's new GC engine I will explain why it is actually needed. This, combined with an introduction how PHP deals with variables in general is explained in this first part of the column. The second part will cover the solution and some notes on the GC mechanism itself, and the third part covers some implications of the GC mechanism, as well as some benchmarks. But now first on to the introduction.
PHP stores variables in containers called a "zval". A zval container contains besides the variable's type and value, also two additional bits of information. The first one is called "is_ref" and contains a boolean value whether this variable is part of a "reference set". With this bit PHP's engine knows how to differentiate between normal variables, and references. However, PHP has user-land references—as created by the & operator, but also an internal reference counting mechanism to optimize memory usage. The second piece of additional information, called "refcount", contains how many variables names—also called symbols—point to this one zval container. All symbols are stored in a symbol table, of which there is one per scope. There is a scope for the main script (ie, the one requested through the browser), as well as for every function or method.
A zval container is created when a new variable is created with a constant value, such as:
$a = "new string";
In this case the new symbol name "a" is created in the current scope, and a new variable container is created with type "string", value "new string". The "is_ref" bit is by default set to "false" because no user-land reference has been created. The "refcount" is set to "1" as there is only one symbol that makes use if this variable container. Also, if the "refcount" is "1", "is_ref" is always "false". If you have Xdebug installed you can display this information by calling:
xdebug_debug_zval('a');
which displays:
a: (refcount=1, is_ref=0)='new string'
Assigning this variable to another variable name, increases the refcount:
$a = "new string"; $b = $a; xdebug_debug_zval( 'a' );
which displays:
a: (refcount=2, is_ref=0)='new string'
The refcount is "2" here, because the same variable container is linked with both "a" and "b". PHP is smart enough not to copy the actual variable container when it is not necessary. Variable containers get destroyed when the "refcount" reaches zero. The "refcount" gets decreased by one for each symbol linked to the variable container leaves the scope (f.e. if the function ends) or when unset() is called on a symbol. The following example shows that:
$a = "new string"; $c = $b = $a; xdebug_debug_zval( 'a' ); unset( $b, $c ); xdebug_debug_zval( 'a' );
which displays:
a: (refcount=3, is_ref=0)='new string' a: (refcount=1, is_ref=0)='new string'
If we now call "unset( $a );" the variable container, including the type and value will be removed from memory.
Things get a tad more complex with compound types such as arrays and objects. Instead of a scalar value, arrays and objects store their properties in a symbol table of their own. This means that the following example creates three zval containers:
$a = array( 'meaning' => 'life', 'number' => 42 ); xdebug_debug_zval( 'a' );
which displays (after formatting):
a: (refcount=1, is_ref=0)=array (
'meaning' => (refcount=1, is_ref=0)='life',
'number' => (refcount=1, is_ref=0)=42
)
Graphically, it looks like:

You can see the three zval containers here: "a", "meaning" and "number". Similar rules apply for increasing and decreasing "refcounts". Below we add another element to the array, and set it's value to the contains of an already existing element:
$a = array( 'meaning' => 'life', 'number' => 4
Truncated by Planet PHP, read more at the original (another 4743 bytes)
In my previous post, I discussed the Closure Compiler’s REST API. In this article, we’ll develop a small PHP program that shows how the API can be used to compress JavaScript code whenever you need it.
Why write your own system?
You’ll find that several free tools handle this task; one of the first PHP JavaScript compressors was written by Ed Eliot. Sometimes, however, they require technologies you don’t use — such as Java — or may not cater for internal workflow processes, including:
- distributing uncompressed JavaScript to developer PCs
- integration with source control systems
- automating your build, and so on
The code below implements a rudimentary JavaScript compressor in PHP to illustrate the basics. The code calls the Closure Compiler compression API every time a request is made, so it’s likely to be slower than multiple uncompressed JavaScript files. You should add your own functions to handle caching to a file or database.
The html
Assume you normally include the following script tags at the bottom of your html:
<script src="script/file1.js"></script>
<script src="script/file2.js"></script>
<script src="script/file3.js"></script>
We’ll replace this block with a single script tag that references all three files.
The .js is removed and the file names are separated with an ampersand:
<script src="script/?file1&file2&file3">
</script>
The PHP
We now require an index.php file within our script folder. The first code block transforms the GET parameters into an array (file1, file2, file3) and initializes the variables:
<?php
// fetch JavaScript files to compress
$jsfiles = array_keys($_GET);
$js = ''; // code to compress
$jscomp = ''; // compressed JS
$err = ''; // error string
We now loop through the JS files, read the content, and append it to the $js string. If a file is unable to be found or read, its name is appended to the $err string:
// fetch JavaScript files
for ($i = 0, $j = count($jsfiles); $i < $j; $i++)
{
$fn = $jsfiles[$i] . '.js';
$jscode = @file_get_contents($fn);
if ($jscode !== false) {
$js .= $jscode . "\n";
}
else {
$err .= $fn . '; ';
}
}
If any files are missing, we can generate a JavaScript alert to inform the developer:
if ($err != '') {
// error: missing files
$jscomp = "alert('The following JavaScript files
could not be read:\\n$err');";
}
If there are no errors and we have some JavaScript code, we can proceed with the compression. The $apiArgs array contains a list of Closure Compiler API options — you can add, remove, or modify these as necessary. The arguments are encoded and appended to the $args string:
else if ($js != '') {
// REST API arguments
$apiArgs = array(
'compilation_level'=>'ADVANCED_OPTIMIZATIONS',
'output_format' => 'text',
'output_info' => 'compiled_code'
);
$args = 'js_code=' . urlencode($js);
foreach ($apiArgs as $key => $value) {
$args .= '&' . $key .'='. urlencode($value);
}
We can now call the Closure Compiler API using PHP’s cURL library. The compressed JavaScript is returned to the $jscomp string:
// API call using cURL
$call = curl_init();
curl_setopt_array($call, array(
CURLOPT_URL =>
'http://closure-compiler.appspot.com/compile',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $args,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 0,
CURLOPT_FOLLOWLOCATION => 0
));
$jscomp = curl_exec($call);
curl_close($call);
Finally, we return our compressed code to the browser with the appropriate MIME type:
}
// output content
header('Content-type: text/javascript');
echo $jscomp;
?>
Download the Code
Truncated by Planet PHP, read more at the original (another 3132 bytes)
On the NerdMom blog there's a recent post from Jen about her experiences in developing in both the CodeIgniter 2 framework and Kohana 3 frameworks (upcoming versions of both).
For the last month or so I've been developing an app side-by-side with Kohana 3 and CodeIgniter 2 to see which framework fits my programming style better. Nothing terribly fancy; just a simple CMS. [...] In the end it comes down to framework stability for me. And in this case, CI wins, hands down. Don't get me wrong; Kohana is beautifully written and introduced me to a prime example of clean, well commented code.
She talks about some of what she was needing out of a framework and what ultimately lead her to pick CodeIgniter 2 as the tool for her and her development. She notes that, while Kohana is nicely written, they've had some consistency issues with backwards compatibility that have caused issues. She also mentions some of the unstable code that was added just to micro-optimize things when it wasn't needed.
<IfModule mod_mime.c>
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
</IfModule>
The non-obvious problem with the above is that it will allow not only "file.php" to be treated as PHP scripts, but also "file.php.txt", which means that any file containing ".php" in its name, no matter where in the filename, would be treated as a PHP script. This of course creates a rather nasty security hole, since many upload file validation tools, only check the final extension. Consequently allowing the user to by-pass the validation, by simply prefixing another "harmless" extension like .txt, .pdf, etc... to the filename, but still get the code to execute.
To mitigate this problem you should instead use the following configuration, that would only pick-up of files ending with a .php extension.
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
The difference between the two configurations being that the original uses AddHandler (bad) and the latter uses AddType (good).
Today I am releasing PHP Manager for IIS 7 – beta, which is an IIS extension for setting up and managing multiple PHP installations on IIS 7 servers. It can be used to:
- Register PHP with IIS;
- Run multiple PHP versions side by side;
- Check PHP runtime configuration and environment (output of phpinfo() function)
- Configure various PHP settings
- Enable or disable PHP extensions
- Remotely manage PHP configuration in php.ini fille
The PHP Manager installation packages can be downloaded from these locations:
The project’s home page and documentation are located at http://phpmanager.codeplex.com/. This blog post describes how the PHP Manager for IIS can be used.
Installation
From the Downloads page select the installation package that is appropriate for your target machine. Download and run the installer, which will install and register PHP Manager’s binaries with IIS. Note that only IIS versions 7.0 and above are supported. After installation is complete, launch the IIS Manager and find the “PHP Manager” feature:
When opened, the “PHP Manager” feature provides a configuration overview for the PHP installation that is registered with IIS and is currently active. If no PHP is registered with IIS, then the only action that can be performed is the registration of a new PHP version.
Registering PHP with IIS
To register a new PHP version with IIS, first you need to download the zip archive with PHP binaries from http://windows.php.net/ and then extract the files from it into a folder of your choice. Note that you can also install PHP by using Web Platform Installer or the Windows installer from http://windows.php.net/ – the PHP Manager can be used to manage those PHP installations as well.
Click on “Register new PHP version” task and then provide the full path to the location of the main php executable file: php-cgi.exe:
After clicking OK the new PHP version will be registered with IIS and will become active. This means that all the sites on this IIS server by default will use this PHP version.
Switching between PHP versions
After multiple PHP versions have been registered with IIS, you can use PHP Manager to easily switch between the versions on a server and site level. This means that you can configure some IIS sites to use one PHP version, while other sites use different version.
Checking phpinfo() output
phpinfo() function in PHP provides very detailed information about all aspects of PHP runtime configuration. To check the phpinfo() output from within PHP Manager use the “Check phpinfo()” task.
Configuring Error Reporting
You can use PHP Manager to configure error reporting level in PHP. If IIS is used on a development machine then you may want to use verbose error reporting in order to see all the errors, warnings and notices from your PHP application right away. If IIS is used as a production server, then error reporting level is less verbose and errors are logged in a log file, but never communicated to HTTP client.
Truncated by Planet PHP, read more at the original (another 2028 bytes)
2010-08-30(月)
They talked about JSClasses, the just launched PHPClasses brother site for JavaScript components.
They also commented on the OpenID based single sign-on system that was implemented to reuse PHPClasses accounts on the JSClasses site to avoid making current PHPClasses users to creating new accounts on the JSClasses site.
It was also discussed about the latest developments for the eventual PHP 5.4 Alpha 1 version, such as the support type hinting of scalar arguments versus strict typing.
Also covered are some initiatives of Michael's company, the JSMag JavaScript magazine (promotion coupon included) and IndieConf, a conference for independent Web professionals.
cakephp1.3 の virtualfieldsについて教えて下さい。
■今回の目的
試験を受けたユーザーが多い順にsortしたい
■DB設定
hideblog_users テーブル として id , name (1対)
hideblog_shikens テーブル として id...
Symfony2 added this week the new ControllerInterface and BaseController classes. The profiler was refactored and the web development toolbar was temporally removed (it will be included in the upcoming WebProfilerBundle). Lastly, the exception management was refactored once more and the event listeners added a new priority parameter.
Development mailing list
- Discussions about Issue with CSRF tokens in forms and Simpler way to enhance standard widgets in client projects
Development highlights
Symfony 1.X branch:
- r30773: [1.3, 1.4] added missing processing of event
Symfony 2.X branch:
- 1277568: [HttpFoundation] fixed Session
- 0319838: [TwigBundle] added a flash tag
- fe78d5f: added a way to disable the profiler
- 9c07e46: [FrameworkBundle] added ControllerInterface. A Controller must now implement ControllerInterface. The BaseController can be used as the base class for Controllers. The Controller class adds some proxy methods and an array access to the Container.
- 789a02d: [FrameworkBundle] and made it call Session::get
- ec8500b: [FrameworkBundle] added support for previous exceptions in the exception pages
- 3c42e0b: [FrameworkBundle] changed the default value of ignore_errors according to the current debug value
- b1e7996: [DependencyInjection] moved extension loading in the freezing process (opens more possibilities in the loading order of configs)
- a432417: [DependencyInjection] added a way to ignore errors when importing a non-existent file (useful when you want to include an optional service file)
- bf67562: [Templating] fixed PHP renderer when using a template variable named 'template'
- 69f9d9c: [DoctrineMongoDBBundle] added logger and data collector for WDT
- 0867080: [HttpFoundation] added a keys() method to *Bag classes
- 1d7f43e: [Framework] added logs when some listeners are not called because the event has already been processed
- 82ff790: added a priority to the event dispatcher listeners
- 57db35b: made ExceptionManager independent of the Request
- 92f4b92: [HttpFoundation] fixed Session serialization
- c78528a: [FrameworkBundle] added abbrClass() and abbrMethod() helpers
- eeb0742: [Framework] added a way to retrieve called and not-called events for a given dispatcher
- 83a64df: added ContainerAwareInterface
- eb66e0d: [FrameworkBundle] made exception controller embeddable
- 72db4c7: refactored Profiler and DataCollector classes (the WDT has been removed and will be re-added in the upcoming WebProfilerBundle)
- 0208800: refactored exception management (removed the ExceptionManager)
sfDoctrinePlugin:
- r30774: [1.3, 1.4] changed lingering Doctrine calls to Doctrine_Core in admin generator
Development digest: 51 changesets, 11 bugs reported, 28 bugs fixed, 4 enhancements suggested, 12 enhancements closed, 7 documentation defects reported, 2 documentation defects fixed, and 12 documentation edits.
Documentation
- New Creating and editing Embedded Forms, and Irc FAQ pages
New symfony bloggers
- Liip Team blog (feed) (English)
- Agence Shape (English, and French)
Plugins
- New plugins
- ggEmailPlugin: helps using the symfony template/layout system for emails.
- idlDropboxPlugin: adds Dropbox features to Symfony project (retrieve account information, upload file, create directories)
- sfOAuthProviderPlugin: allows you to turn your application to an oauth provider.
- sfHarmonyFlexPlugin: (no description)
- sfHarmonySoapPlugin: (no description)
- sfHarmonyOAuthPlugin: (no description)
- lyMediaManagerPlugin: refactored lyMediaAsset and added some unit tests, refactored lyMediaFolder, fixed wrong rounding to integer of asset file size value
- csDoctrineActAsSortablePlugin: fixed fetchOne for large Collections
- csDoctrineActAsGeolocatablePlugin: fixed incorrect error message in geolocatable template
- sfAssetsLibraryPlugin: fixed some small issues in helper and routing, improved README, fixed some issues with sfWidgetFormAssetInput
- ddOnlineStorePlugin: the fixtures files now are .sample files, is_featured field added to all products
- sfFormExtraPlugin: added support for sfWidgetFormDateTime in sfWidgetFormJQueryDate, fixed JS function names when the widget name contains '-', fixed sfWidgetFormJQueryDate doesn't restrict values on page load, fixed sfWidgetFormJQueryDate doesn't refresh disabled after the date was chosen from calendar, updated the autocomplete JavaScript to the latest version, added culture and theme options for sfWidgetFormReCaptcha, fixed widget for sfFormLanguage, allowed unassociated list to be left of the associated one
- sfDatgridPlugin: clear also hidden in jquery reset search
- sfTaskLoggerPlugin: fixed bug with logger when the task is launched in a web context: need to disconnect from dispatcher to avoid symfony to try to write in the closed file
- sfPropel15Plugin: fixed plugin package template (remember to modify the package generated by the plugin:package task to remove the vendor/propel-generator/pear/build-pear-package.xml file, since it makes PEAR go nuts when trying to install the package)
- ahDoctrineEasyEmbeddedRelationsPlugin: added newFormUnsetPrimaryKeys optional parameter (this allows you to embedded forms to not unset their primary keys, this is useful in composite key situations)
- sfAdminDashPlugin: updated translations
- diemProject:
- fixed permission name in dmWidget/editRecords security
- swap assets in asynchronous rendering of widget
- apostrophePlugin:
- added more a_include_js_calls() invocations to AJAX actions which don't get it automatically
- fixed aMediaCMSSlotsTools had a redundant and buggy implementation of aMediaTools::userHasUploadPrivilege()
- the repair-tree task has been overhauled (all variants of the task now use PDO to avoid running out of memory on big page trees)
- the repair-tree task has been overhauled (all variants of the task now use PDO to avoid running out of memory on big page trees)
- added javascript to hide the template dropdown if your page type is not template-based
- navigation component can now accept its active and root parameters as aPage objects
- removed assumptions about routes
- removed second instance of history browser from global tools
- refactored big chunks of inline js to the apostrophe object and a_js_call
- updated the edit categories funcitonality in the media lib sidebar to use a_js
- the versions info array is now a flat array for JS compatibility
- aDoctrineRoute and aRoute can no longer require an additional query to be made when using the engine-slug parameter
- apostropheBlogPlugin:
- backed out engineSlug in blog plugin
- fixed count query used for blog category admin
- changed link_to to use named route in blogCategoryAdmin
- fixed a bug that was causing the categories listing in the page settings engine dropddown to not be alaphabetical
- added first pass at a calendar for events
- removed obsolete tasks that just lead to confusion
- fixed i18n: apostropheBlogPlugin should use the apostrophe catalog just like the main plugin does
- added some more functionality to the calendar so you can click on a day, month or year and begin browsing that way
- fixed calendar for showSuccess and changed the getDay getMonth getYear for events to use the StartDate instead of the Pub Date
- removed the addStylesheets and addJavascripts calls from the assets partial
- moved the app.yml check for whether or not the calendar is enabled up into the action
- Billigt Grin: (Danish) a danish booking agency for upcoming stand-up comedians
- Kvartirka.bg: (Bulgarian) find appartments for rent in Bulgaria
- PressBulgaria.com: (Bulgarian) send press release to all medias in Bulgaria
They talked about us
- Setting up Continuous Integration for a symfony plugin using Hudson and Sebastian Bergmanns (PHPUnit) Template for Hudson Jobs for PHP Projects
- Liip at FrOSCamp
- Symfony Day Köln 2010
- Symfony – Storing email templates in XML for use with sfMailer
- phpBB 4 будет на Symfony 2
- What would you expect of a best practice document when developing symfony 1.4 form widgets?
- Using JaSig CAS with Symfony
- Petite approche de Doctrine (partie 2)
- Petite approche de Doctrine (partie 3)
- Applying best practices for PHPUnit testing symfony plugins
- Why Doctrine_Core::getTable(‘BarFoo’) is not such a good idea.. when PHPUnit testing a symfony plugin
- Multiples connexions doctrine et le chargement des modèles
- Apostrophe CMS – изменение стандартной слугофикации (slugify)
- Symfony Visualization
- symfony popup with jQuery thickbox - beginner's tutorial
- 国外开源PHP框架集合
- Symfony fejlesztés
- Erreur symfony: la mauvaise connexion est utilisé lors de la requête avec Doctrine
- Faire le ménage dans votre dossier modèle
- PHP Libraries, Frameworks, and Tools
- Symfony: gestion de document; lecture/écriture
- Symfony and MVC - follow up
- Sending multipart email from a Task in Symfony 1.4
- Overview of PHPEdit extension for Symfony
- Configurar Symfony 1.4.x desde cero sobre Ubuntu 10.04
- Selenium and symfony Integeration – the Non-plugin Approach (Tutorial)
- Symfony 1.4 -ийг хамгийн амархан тохируулах арга
- Is your task running out of memory?
- Symfony – Storing email templates in XML for use with sfMailer
- Ömrümü yedin Symfony
- phpBB 4 на Symfony 2
- Building PHP Web App in 15 minutes with Symfony Framework
style="margin-bottom: 5px">

digg に投稿する
del.icio.us に追加する
はてなに追加する




