News Feed

News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Derick Rethans:
Xdebug 2.3 Moar var_dump()
February 27, 2015 @ 09:58:40

Derick Rethans has a new post to his site starting a series of posts about the new features of Xdebug 2.3. In this new post he talks about an improvement that's been made to the output provided by var_dump with more information than before.

One of the new features relates to one of the first things that I added in the original Xdebug: making the var_dump() output "pretty". Xdebug replaces PHP's standard var_dump() function with its own version, as long as the xdebug.overload_var_dump setting is not set to 0. [...] Xdebug 2.3 enhances the overloading of var_dump() with the inclusion of the file name and line number where var_dump() is called at. This has been a long standing feature request.

He provides a few sample screenshots comparing the old and new output formats and mentions another handy setting, xdebug.file_link_format, that makes the resulting filename a link in a browser and lets you customize the format.

0 comments voice your opinion now!
xdebug vardump overload file path information output improvement release


Phil Sturgeon:
Composer It's ALMOST Always About the Lock File
November 05, 2014 @ 11:44:49

In his latest post Phil Sturgeon talks about a point that's been argued on both sides of the Composer users out there - whether or not to commit the "composer.lock" file. Phil talks some about it in his article and suggests that you should commit it for applications but not for components.

If you and your employees are a little vague with your composer.json specifications and you don't have a composer.lock then you can end up on different versions between you. Theoretically, if component developers are using SemVer and you're being careful then you should be fine, but keeping your lock in version control will make sure that the same version is on your dev teams computers. This will happen every time you run $ composer install. If you are on Heroku or EngineYard then this will be used for the deployment of your production components as a built in hook, which is awesome.

He mentions an article from Davey Shafik, this being his reaction to it. He suggests, though, that an absolute of "always commit for components" may be too much and could potentially cause other problems. He points out that since the "composer.lock" handling is local to the directory, you can hit up against version requirement issues between them in your application as a whole. He wonders "how strict is too strict" when defining dependencies and some things to think about (like your users) when making the choice to upgrade the libraries you use.

0 comments voice your opinion now!
composer composerlock file commit version semanticversioning semver component application


Zumba Tech Blog:
Caching CakePHP 2.x routes
October 28, 2014 @ 10:47:02

On the Zumba Tech Blog today there's a new post with some helpful hints around caching routes in CakePHP 2.x to help optimize the requests and response time even further.

At Zumba we are continuously looking for optimization in our applications. These optimizations help to reduce the server loads, consequently reducing the number of servers and saving money. Besides that, it gives a better user experience for the end user by serving content faster and in some cases saving on consumer bandwidth (specially for mobile users). This week we profiled our app using Xdebug profiler and we identified the router was responsible for a big part of the request time. [...] In order to optimize the routing time, we started looking at options to optimize our routing process. After some research and deep checking in our codebase as well as CakePHP's code, we found we could cache the routes easily.

Taking a cue from how FastRoute does their caching, their implementation uses a temporary file with the routes completely resolved and written out for easier handling. Since the routing is relatively static, this method works well and can be much faster than resolving them every time. They talk about some of the work done to optimize their method and some of the issues they came across during the process.

0 comments voice your opinion now!
cakephp framework cache route file resolve


Rob Allen:
Throw an exception when simplexml_load_string fails
September 09, 2014 @ 09:27:13

In a quick post to his site Rob Allen shares a class that he's created to handle and throw an exception any time that the load from a SimpleXML parsing fails.

I keep having to look up how to stop the warning that are emitted when simplexml_load_string & simplexml_load_file fail, so this time I've written the world's simplest little class to take care of it for me from now on.

His "Xml" class wraps around the SimpleXML functionality and checks to see if the resulting object is false. If it is, it uses some internal error handling to fetch the error message result and throws it as a "RuntimeException". This error string comes from a "getXMLErrorString" function that uses the libxml_get_errors function to get the resulting error list.

0 comments voice your opinion now!
simplexml load string file fail exception error handling


SitePoint PHP Blog:
Diffbot Crawling with Visual Machine Learning
August 01, 2014 @ 11:37:12

On the SitePoint PHP blog Bruno Skvorc has posted a tutorial showing you how to use the Diffbot service to extract data from any page. He introduces both the service itself and walks you through a simple request via Guzzle.

Have you ever wondered how social networks do URL previews so well when you share links? How do they know which images to grab, whom to cite as an author, or which tags to attach to the preview? Is it all crawling with complex regexes over source code? Actually, more often than not, it isn't. [...] If you want to build a URL preview snippet or a news aggregator, there are many automatic crawlers available online, both proprietary and open source, but you seldom find something as niche as visual machine learning. This is exactly what Diffbot is - a "visual learning robot" which renders a URL you request in full and then visually extracts data, helping itself with some metadata from the page source as needed.

He uses a combination of a Laravel installation (via a Homestead instance) and a Guzzle request using a fetched token. The service offers a 10k call limit on a 7 day free trial, so you can sign up and grab your token there. He includes code for an example request fetching a SitePoint page and parsing out the tags. He also briefly looks at the custom handling diffbot allows based on CSS-type rules.

0 comments voice your opinion now!
diffbot parse data service api guzzle homestead tutorial introduction


Joshua Thijssen:
Internal PHP function usage
July 28, 2014 @ 10:05:39

Curious about the usage of the various "internal" (built-in, not user defined) functions in use is a wide range of PHP applications, Joshua Thijssen did some research on GitHub and has shared the results on his site today.

How many internal PHP functions (things like count(), strpos(), array_merge() etc), does PHP have? Depending on which version you use, and how many extensions you have loaded, somewhere between 1000 and 2000 would be a good guess. But how many of these internal functions are you REALLY using?

He created a custom script to fetch the results of a custom query (one that found repos with over fifty stars), grabbed the source and parsed the results looking for these internal functions. He shares the results of his parsing from 967 repos in the remainder of the post, including: the top ten most called, some interesting facts found in the results and some of the "bad" ones in wide use (like "exec" and "mysql_connect").

0 comments voice your opinion now!
internal function usage statistics github parse query


Master Zend Framework:
Create a Simple File Upload Form in Zend Framework 2
June 04, 2014 @ 11:51:06

On his "Master Zend Framework" site today Matthew Setter has a new tutorial showing you how to create a simple file upload through the forms handling in Zend Framework 2. The form will include three parts: an input filter, a form class and a controller action to request to show the resulting form.

Having trouble getting file uploads integrated into your forms in Zend Framework 2? Or are you just curious about how to do it, and you want a quick rundown? If either of these is you, come walk through today's post with me as I show you a simple example of how it's done - along with how to combine it with filters and validators. Before we get started, I could have composed the code in a much shorter form than have I've composed it. But my assumption is that you're likely using the full-stack framework.

He includes summaries describing each of the three parts of the setup and the code you'll need to create each. The validator checks for things like "too big", "too small" and the correct MIME type on the file given. The form itself only includes the file upload element with a description of "Attachment". The controller action creates the form instance and calls an "isValid" when the upload happens to execute the validation. He also throws in the view template to display the form itself.

0 comments voice your opinion now!
zendframework2 simple file upload tutorial form

How to use the "yield" keyword in PHP 5.5 and up
May 23, 2014 @ 12:09:47

In a recent post to the LeaseWebLabs blog Maurits van der Schee looks at the use of the "yield" keyword in PHP 5.5 to work with generators. A generator is very similar to a function that returns an array, in that a generator has parameters, can be called, and generates a sequence of values but it yields values one at a time.

The concept of generators is not new. The "yield" keyword exists in other programming languages as well. As far as I know C#, Ruby, Python, and JavaScript have this keyword. The first usage that comes to mind for me is when I want to read a big text file line-by-line (for instance a log file). Instead of reading the whole text file into RAM you can use an iterator and still have a simple program flow containing a "foreach" loop that iterates over all the lines.

He includes a few code examples showing a class that can read in data from a file in chunks and output the lines as they're extracted (versus using something like file). He also talks about a small performance comparison in working with the file pointer, fread over fgets. He even makes a simple benchmark script to compare the overall time and memory consumption of the fetching of different byte "chunks" from the file.

0 comments voice your opinion now!
yield generator file read fread fgets memory time benchmark


SitePoint PHP Blog:
Introduction to Kirby CMS
April 28, 2014 @ 13:48:31

The SitePoint PHP blog has posted a new article introducing you to Kirby, a database-less content management system that's all file based.

Kirby is a lightweight CMS that probably fits somewhere between feature-rich platforms such as Drupal, and static site generators such as Jekyll. What makes Kirby quite different to most CMS's - and closer to Jekyll in the process - is that it has no database. Instead, everything is stored as files; some for configuration, some for content - all in addition to the usual template files, partials and plugins. In this article I'm going to take a look at Kirby, demonstrate how to use it, and assess some of its strengths and weaknesses.

He walks you through the download and installation process and provides a general overview of the structure of the application and how it works. He gets into the specifics of theming the site to match your own look and feel, shows you how to use "kirbytext", a custom extension of Markdown. He also briefly covers plugins, the main panel and some of the pros and cons of using the system.

0 comments voice your opinion now!
kirby cms content management system file


Edd Mann:
Storing PHP Sessions/File Caches in Memory using TMPFS
April 17, 2014 @ 11:19:59

Edd Mann (of the Three Devs & A Maybe podcast) has shared a method of session storage he worked up to help increase performance in his application. He shows how to store sessions in memory with the help of TMPFS.

Yesterday I was looking through some application logs and noticed a significant bottleneck with I/O reads in the implemented file cache. [...] This was when I found 'tmpfs', saving me from all sorts of issues relating to adding yet another application to the production stack. 'tmpfs' appears as a mounted partition on your system, however, under the hood it allocates and uses a section of physical memory (non-persistent through reboots). [...] his results in the desired speed boosts, without tampering with the application logic itself. Even better, if the mount is unsuccessful for some reason, it will safety fall-back to using the persistent hard-disk solution.

Since PHP sessions make it easy to change the "save_path" location for the data in an ini value, setup is easy. He includes the needed configuration change and the commands you'll need to mount the tmpfs partition on your local file system.

0 comments voice your opinion now!
tmpfs session file cache memory tutorial comamnds ini


Community Events

Don't see your event here?
Let us know!

unittest voicesoftheelephpant library symfony opinion interview series framework language version community api threedevsandamaybe podcast laravel laravel5 security extension release introduction

All content copyright, 2015 :: - Powered by the Solar PHP Framework