2012年7月3日星期二

Community News: Latest PECL Releases for 07.03.2012

Latest PECL Releases:

VG Tech Blog: Using Elastica to Query ElasticSearch


On the VG Tech blog today there's a new post by Christer Edvartsen about using the Elastica PHP Elastic Search client to do more than just pull information out of the data source. He dug into the source of the tool itself and figured out a way to perform actual queries.



The last couple of months I have been playing around with elasticsearch, an open source, distributed, RESTful search engine built on top of Apache Lucene. To interact with elasticsearch in PHP I have been using a client called Elastica. This was all fun and games until I needed to do actual queries, which is what our users will be doing most of the time. Elastica's documentation does not (yet) say anything about how to search using the client, so I needed to dig through the code to see if I could find some solutions.


He includes a sample mapping structure and shows how to take both a simple, single-term query and turn it into a request and how to make a more complex request with filters, facets, sorting and a few other things thrown in. He also shows how you can manually create a query (define the JSON structure yourself) and push that into the "query builder" for handling.

PHPMaster.com: Automate PSR Compliance through Jenkins


On PHPMaster.com today there's new tutorial showing how you can enforce compliance with the PSR standards in your application's code with the help of the Jenkins continuous integration tool.



Though it's still early to guarantee that the PSRs will be widely adopted as the de facto standard for writing serious PHP applications, it is interesting to note that a code sniffer and fixer that looks for code deviations was developed by nobody less than Fabien Potencier, the creator of the Symfony framework. (Et bien, ils ne sont pas fous, ces français!) In the rest of the article we shall find out what his PHP-CS-Fixer does and how can it be integrated with a CI tool like Jenkins.


He shows how to install a tool that can help you keep your source in compliance - the "fixer" (created by Fabien Potencier) to help correct the problems found in your code. He includes the command line calls you'll need to run the tool on your code and how to add the step to your build.

DZone.com: All the ways to perform HTTP requests in PHP


On DZone.com there's a recent post from Giorgio Sironi listing out some of the HTTP client utilities that can be used in your PHP applications.



In the PHP world, HTTP is very important: not only for receiving requests, which is the job of PHP application, but also for performing them. ROT web services are probably the most popular way to interface with external systems nowadays. We'll make no assumptions on the payload of HTTP requests (which may be binary, text, JSON, XML), so you'll have to deal with that yourself. In some cases, you may choose a more specific solution such as the SoapClient class in the SOAP extension, or the XML-RPC extension.


Among the methods he mentions are things like the cURL extension, fsockopen and the PECL HTTP extension. He also talks about some of the libraries out there that are popular among developers (Buzz and Guzzle) as well as the modules included in the Zend Framework (v1 and v2) to make the requests.

2012年7月2日星期一

PHPMaster.com: 5 Inspiring (and Useful) PHP Snippets


On PHPMaster.com there's a new tutorial that shares some useful PHP snippets that you could use in your development.



"X PHP Snippets" type articles abound on the Internet, so why write another one? Well, let's face it… the PHP snippets in them are generally lame. Snippets that generating a random string or return $_SERVER["REMOTE_ADDR"] for the IP Address of a client really aren't that interesting and are of modest usefulness. Instead, here's five snippets that you'll no doubt find interesting and useful, presented along with the problems that inspired them. I hope the creativity in many of them inspire you to write better and more creative code in your own day-to-day endeavors.

Their "five tips" are about:



  • Generating CSV files from an array of data
  • Autoloading classes (in a PSR-0 way)
  • Parsing data with the unpack function
  • Templating in HTML (creating a "View" object)
  • Using file_get_contents as a cURL Alternative

Jeff Atwood's Blog: The PHP Singularity


In case you missed it (there's been a good bit of buzz about it in the PHP community lately) there's a recent post from Jeff Atwood about the PHP language and some of his thoughts on its usefulness, it's structure and some of this thoughts on the usual "PHP sucks" kinds of articles.



Remember the immediate visceral reaction you had to the double-clawed hammer? That's exactly the reaction most sane programmers have to their first encounter with the web programming language PHP. This has been going on for years.


He talks about the the anti-PHP rants that have been happening (over and over) for years, his thoughts on it being the "worst designed mainstream 'language'" out there...and how the discussion doesn't need to be around these points anymore. It needs to be about how to get programmers to use better tooling (whether or not PHP is the right tool for the job).



Of course, there's no shortage of comments on a post like this, so be sure to go through them and see the various reactions to Jeff's thoughts.