 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
PHPMaster.com: Using SPL Iterators, Part 1
by Chris Cornutt May 15, 2012 @ 12:26:59
On PHPMaster.com today there's a new tutorial posted, the first part of a series, looking at the use of the Standard PHP Library (SPL) in PHP. In this first part of the series, Stefan Froelich looks specifically at two of the more common uses for iterators - working with arrays and directories.
When I first came across the term iteration and saw the overwhelming list of classes related to it in the SPL, I was taken aback. It seemed maybe iteration was too complex for me to grasp. I soon realized it was just a fancy word for something we programmers do all the time. [...] In the first part of this two-part series I'll introduce you to iteration and how you can take advantage of some of the built-in classes from the Standard PHP Library (SPL).
Included in the tutorial is example code showing how to use the ArrayIterator to work with an array and the DirectoryIterator to process the contents of a directory. He also briefly touches on a few other iterators like "FileExtensionFilter", "RecursiveDirectoryIterator" and "RecursiveArrayIterator".
voice your opinion now!
spl iterators tutorial array directory file recursive
Larry Garfield's Blog: readfile() not considered harmful
by Chris Cornutt May 04, 2012 @ 09:51:38
In this new post to his blog Larry Garfield tries to dispel a common misconception in the PHP development world - that the readfile function should be considered harmful and can cause memory issues in your code.
If you're like me, you've probably read a dozen or two articles about PHP performance in your career. Many of them are quite good, but some are simply flat out wrong, or misinformed. One of the old truisms that has been repeated for as long as I can recall is "don't use readfile() if you have big files, because it reads the whole file into memory and your server will explode." [...] There's just one problem with that age-old truism: It's not true.
He created some benchmarks to illustrate the differences between several of the common methods for working with files via the fread, fpassthru, stream_copy_to_stream and of course readfile. He reports the results based on the runtime and the peak memory usage and noted, ironically, that while the times varied slightly, the memory consumption was exactly the same for all of the approaches. Since there's no real reason not to use "readfile", he looks at three reasons why there might be this stigma attached to it (including the issues that could come up with output buffering enabled).
voice your opinion now!
readfile file handling harmful dispel myth benchmark memory
PHPMaster.com: Working with Files in PHP
by Chris Cornutt 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).
voice your opinion now!
file filesystem tutorial example
Phil Sturgeon's Blog: Hijacking Headers to Force Downloads
by Chris Cornutt March 29, 2012 @ 11:29:28
Phil Sturgeon shows how you can hijack headers in his latest post to force a download to the client (even on a hosted service like PagodaBox).
The question [I posed on Twitter] was: "How to force a download of any file of any type, not on your server, without Apache tweaking? Images are displaying and need em to download." Essentially, I wanted to be able to link to a file that was not on the server in question and anywhere in the world, which could be of any size, any media type and could be potentially very high traffic.
Answers varied from using readfile to just letting the browser handle it. None of the responses were quick right until he came across one that recommended some settings in an .htaccess file. It uses
voice your opinion now!
file download force header question htacess
Gonzalo Ayuso's Blog: How to use eval() without using eval() in PHP
by Chris Cornutt March 13, 2012 @ 10:09:52
In this new post Gonzalo Ayuso talks about "using eval without using eval" in PHP applications - executing PHP code without having to use the eval function to do it.
Yes I know. Eval() is evil. If our answer is to use eval() function, we are probably asking the wrong question. When we see an eval() function all our coding smell's red lights start flashing inside our mind. Definitely it's a bad practice. But last week I was thinking about it. How can I eval raw PHP code without using the eval function, and I will show you my outcomes.
He includes some sample code showing a basic script with a class and a loop executing normally, then an "eval version" that puts it all in a string and executes it. He offers a different method - not an ideal one since it requires being able to write to the local file system, but prevents the need for eval - writing the PHP code to a temporary file and using a "fake eval" to pull it in.
voice your opinion now!
eval execute string code temporary file include
DevShed: PHP Closures as View Helpers Lazy-Loading File Data
by Chris Cornutt January 30, 2012 @ 13:08:28
In the second part of their look at using closures in PHP as view helpers, DevShed improves upon their original code by adding some additional classes and using them in the closures.
The best way to show you how using anonymous functions can help you to develop more efficient OO applications is with some functional, hands-on examples. With this idea in mind, in the installment that preceded this one, I implemented an extendable template system. This system could spawn view objects and render the template files associated with these objects.
In this second part of the (two-part) series they include "Serializer" and "FileHandler" classes and show how to use them inside of the closures to lazy-load in data from an external file and work with it as serialized content.
voice your opinion now!
tutorial closure lazyload file serialize view helper
PHPMaster.com: A Tour of PHP.INI
by Chris Cornutt December 12, 2011 @ 10:42:45
On PHPMaster.com today Callum Hopkins has written up an introduction to the php.ini, the heart and soul of any PHP installation. With configuration options for just about everything, it can be confusing. This tutorial hits some of the highs and most commonly updated settings.
Anyone who has a server using PHP has undoubtedly heard of php.ini - it's the configuration file used to control and customize PHP's run-time behavior. It provides a simple way to configure settings. [...] In this article I'll give an overview of some important settings I believe you should be concerned with when tweaking your own php.ini file.
The tutorial's broken up into a few different topics:
- the PHP engine
- Short tags
- Output buffering
- Automatic headers and footers
- Handling errors
- Time zones
voice your opinion now!
phpini configuration tutorial file setting
DevShed: File Security and Resources with PHP
by Chris Cornutt November 23, 2011 @ 16:23:27
In the fourth part of their series looking at working with the filesystem in PHP, DevShed has posted a new tutorial focusing on security and permission handling for files/resources.
These days, security is paramount to any server installation, large or small. Most modern operating systems have embraced the concept of the separation of file rights via a user/group ownership paradigm, which, when properly configured, offers a wonderfully convenient and powerful means for securing data. In this section, you'll learn how to use PHP's built-in functionality to review and manage these permissions.
They introduce functions like:
Sample code is also included to show how to open and close a file.
voice your opinion now!
file security resource permissions function tutorial
|
Community Events
Don't see your event here? Let us know!
|