News Feed
Sections




News Archive
feed this:

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

SitePoint PHP Blog:
Abstract File Systems with Flysystem
April 07, 2014 @ 11:27:59

The SitePoint PHP blog has a new tutorial today from Lukas White showing you how to work with abstract file systems that aren't local. In this case, the file system is virtual and living on a remote system.

Reading and writing files is an integral aspect of any programming language, but the underlying implementation can vary enormously. For example, the finer details of writing data to the local filesystem compared to uploading over FTP is very different - yet conceptually, it's very similar. In addition to old warhorses like FTP, online storage is increasingly ubiquitous and inexpensive - with scores of services available such as Dropbox, Amazon's S3 and Rackspace's Cloud Files - but these all use subtly different methods for reading and writing. That's where flysystem comes in.

He shows how to install the flysystem library (via Composer) and a few examples showing how to make connections to:

  • an Amazon S3 instance
  • a Dropbox account
  • SFTP
  • even Memcache

Examples of both reading and writing to this virtual system are also included as well as a few other features like handling visibility, listing files/directories and mounting the remote filesystem locally.

0 comments voice your opinion now!
abstract filesystem flysystem library tutorial

Link: http://www.sitepoint.com/abstract-file-systems-flysystem

PHPBuilder.com:
Clustered File Systems and PHP
November 21, 2013 @ 10:22:38

On PHPBuilder.com today they continue their series looking at working with clustered file systems and PHP with this new post, the second part in the series (part one is here).

In part one, Introduction to Clustering in PHP, we explored the concepts of load balancing, PHP sessions, and how to set up a rudimentary PHP cluster that allows for redundancy as well as load balancing. The final configuration was one load balancer exposing an NFS share for all of the client PHP servers to use for session storage. While effective, this still gives us a single point of failure (the load balancer). More load balancers can be added, but sits us squarely back on our original problem: All of the sessions are on the first load balancer, not the second.

They talk about the GlusterFS networkable file system and talk about its concepts of "drives" and "bricks". The rest of the post is centered around helping you get GlusterFS servers set up and a brief mention of pointing your PHP session storage to the resulting setup.

0 comments voice your opinion now!
cluster filesystem session glusterfs install configure

Link: http://www.phpbuilder.com/articles/application-architecture/optimization/clustered-file-systems-and-php.html

Kevin Boyd:
Retrofitted Login Throttling
July 26, 2013 @ 11:56:29

In this new post to his site Kevin Boyd introduces a tool that you can use to scan your logs for login abuse, Fail2ban, and how to use it with your application's login attempts to ban IPs as needed.

Fail2Ban is a Python-based utility that hooks directly into the system's firewall to ban malicious IP addresses, and I'm going to show a few easy steps to make your site safer by blacklisting brute-force attackers. If you maintain a web application that doesn't have built-in authentication throttling, this might be the how-to you're looking for - alternatively, this would work as an additional way to punish pesky rogue connections.

His example uses the Fail2Ban ability to read files on the local system, as written by PHP and containing the failure message and an IP address, and adds IP blocks accordingly. He includes some sample code for the format you'll need to follow and a bit about setup and configuration of the Fail2ban tool.

0 comments voice your opinion now!
login throttling fail2ban tutorial filesystem log tutorial

Link: http://whateverthing.com/blog/2013/07/24/fail2ban-login-throttling

PHPMaster.com:
Working with Files in PHP
April 24, 2012 @ 10:05:41

On PHPMaster.com today there's a new tutorial that shows you some examples of working with files and the local file system in your PHP applications.

You may well be familiar with databases such as MySQL and Access which are an ever-increasingly common means of storing data. But data is also stored in files, like Word documents, event logs, spreadsheets, image files, and so on. Databases generally require a special query language to retrieve information, whereas files are 'flat' and usually appear as a stream of text. [...] PHP provides a range of functions which allow you to work with files, and in this article I'll demonstrate some of them for you.

Examples in the article include the use of several of the PHP file functions including: filesize, filectime, is_readable, file_put_contents and fopen. There's also an example of using the CSV file functions for working with a comma-separated file (both in reading and writing).

0 comments voice your opinion now!
file filesystem tutorial example


Stefan Koopmanschap's Blog:
GlobIterator Easy access to specific files
April 17, 2012 @ 12:43:42

Stefan Koopmanschap has a new post to his blog showing a handy use of the GlobIterator to access only certain files.

For a project I am working on I needed to iterate over all .xml files in a specific directory. I started out with a DirectoryIterator, then considered I didn't want the XML filtering to take place inside my foreach loop. I decided to add a FilterIterator to the setup, but then felt this was not the right solution either. So I turned to my favorite SPL guru, Joshua Thijssen, to see if I was overseeing some kind of filter-option in the DirectoryIterator. I didn't, but I did oversee something else: GlobIterator.

The GlobIterator lets you use functionality similar to the glob function (including being able to use wildcards in file searching) and get the resulting list back as a set of SplFileInfo objects, complete with additional metadata that can be extracted.

0 comments voice your opinion now!
globiterator spl iterator glob filesystem find


Sebastian Göttschkes' Blog:
Using vsfstream (with symfony2)
April 05, 2012 @ 11:32:50

In this recent post Sebastian Göttschkes shows how to use the vfsStream stream wrapper in a Symfony2 application to create tests that involve the local file system.

I read about vsfstream when skipping through the phpunit docs. Back then, I decided I don't need a virtual file system. Some time later, I had to test classes which read and write files and found myself creating and deleting temporary folders, messing around with nasty errors (like my favourite one where for some reasons tests fail when I don't use @runTestsInSeparateProcesses).

He walks you through the install process, how to register it in the Symfony2 autoloader (so you don't have to include the files each time) and how to include it (via namespace-based loading) in your tests.

0 comments voice your opinion now!
vfsstream symfony2 tutorial filesystem unittest phpunit


VG Tech Blog:
Mocking the File System Using PHPUnit and vfsStream
December 09, 2011 @ 09:40:13

On the VG Tech blog today there's another post related to unit testing (here's one from before) but this time they're talking about mocking the filesystem with vfsStream, a powerful tool that lets you interact with PHP streams as a virtual file system.

This article is about how to mock the file system when writing unit tests, and it will be rather code-heavy. [...] PHPUnit is the de-facto standard for unit testing in PHP projects, and this is what we will be using together with vfsStream in this article.

The include the code for a simple storage driver (VGF_Storage_Driver_Filesystem) to use with vfsStream with "store", "delete" and "get" methods. Also included are examples of using vfsStream to check things like directory existence, if a file exists, or if a file can be read. A few simple assertions are set up in their sample test to check the methods in their "VGF_Storage_Driver_Filesystem" class.

0 comments voice your opinion now!
unittest phpunit vfsstream tutorial filesystem mock


XpertDeveloper.com:
PHP clearstatecache() Explained
September 22, 2011 @ 09:21:40

XPertDeveloper.com has a quick new post looking at a function that might be overlooked until it suddenly becomes just what you need - clearstatecache for clearing file state information in the current script.

For the functions like is_file(), file_exists(), etc PHP caches the result of this function for each file for faster performance if function called again. But in some cases you want to clear this cached information, for the task like getting the information of the same file multiple times in same page.

Other methods this cache effects include stat, file_exists, is_file and more. If the state of a file is changed during the course of the script - say it's deleted manually, not by PHP, your script may not recognize that. By calling clearstatecache, you refresh this cache and make it possible to see the latest file system info.

0 comments voice your opinion now!
clearstatecache tutorial filesystem state file


Lars Tesmer's Blog:
How to Unit Test a Class Making Calls to an URL (or the Filesystem) With PHPUnit
September 21, 2011 @ 12:04:47

Lars Tesmer has a suggestion for all of the unit testers out there (you do unit test your code, right?) when needing to test a piece of code that makes a call to something on the file system or a remote resource. Their examples come from tests written against the Assetic codebase.

For our most recent After Work Hacking my co-workers and me decided to write unit tests for the open source project Assetic. That turned out to be a better decision than our last one, yet we still ran into an interesting challenge.

In testing the HttpAsset class from the tool, they came across the problem - a call to a remote/file resource that could not be tested because of a file_get_contents call that depends on an external source. They came up with a few options to try to test this example, some better than others:

  • Give it a real URL to test with
  • Wrap the file_get_contents inside of a new class (ex. a "ContentFetcher")
  • Use vfsStream to mock out the file system in the unit test

In their case, vfsStream couldn't be used due to how the fetch call was made, but the tool can be very handy if you need to mock out an external file system resource.

0 comments voice your opinion now!
phpunit unittest remote url filesystem resource mock vfsstream


DevShed:
Cache Data in RAM with PHP
June 08, 2011 @ 10:48:23

DevShed has posted a new article in their series looking at storage interfaces and how to use them. In this latest article they show how to create a caching layer that will allow you to work with any sort of caching backend you'd like.

As with other elements of object-oriented programming, it's possible to use segregated interfaces in a great variety of scenarios and conditions and, therefore, enjoy the benefits that they provide right out of the box. [...] My goal in this article is to create an extendable caching system based on the contract defined by a segregated interface. To achieve this, the first step we need to take is to create the interface in question.

He shows how to create the "CacheableInterface" that provides the structure for the child interfaces to follow. It provides methods for setting, getting, deleting and checking to see if a key exists. They illustrate its use with an interface to an APC cache, a file caching and a class that uses dependency injection to define the interface to use.

0 comments voice your opinion now!
caching data ram tutorial apc filesystem interface



Community Events





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


bugfix threedevsandamaybe series framework conference code release interview list language zendserver api development tips introduction symfony community podcast laravel deployment

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework