 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Gonzalo Ayuso's Blog: Checking the performance of PHP exceptions
by Chris Cornutt January 17, 2012 @ 08:02:24
Gonzalo Ayuso has a new post to his blog today looking at the performance of PHP exceptions and how it could effect your application's overall speed.
Sometimes we use exceptions to manage the flow of our scripts. I imagine that the use of exceptions must have a performance lack. Because of that I will perform a small benchmark to test the performance of one simple script throwing exceptions and without them.
His (little) benchmarking scripts are included - both looping 100000 times, one throwing an exception and the other not. The results were pretty obvious - the memory usage was about the same but the speed was about ten times faster without the exceptions (in PHP 5.3). In PHP 5.4, however, the numbers were closer as far as time to run. Obviously, unless you make super heavy use of exceptions, you're not even going to come close to something like this (micro-optimization anyone?).
voice your opinion now!
exception performance benchmark execution time memory
Slawek Lukasiewicz's Blog: Working with date and time in object oriented way
by Chris Cornutt June 10, 2011 @ 08:13:14
Slawek Lukasiewicz has a new post today about working with dates and times in PHP on a more object-oriented fashion than in the more traditionally procedural way of just calling PHP date/time functions on the string values.
Date and time manipulation in PHP is mostly connected with functions like: date, time or strtotime. They can be sufficient, but if we want to deal with dates like with objects - we can use DateTime class. DateTime class is not only straightforward wrapper for standard functions, it has a lot of additional features - for example timezones.
He shows how to use the DateTime functionality to return an object you can call several different methods on. He gives examples of the formatting call, comparing one DateTime object to another, how to update the date after the object's created, calculating the difference between two dates and iterating through a certain time period.
voice your opinion now!
time date datetime objectoriented procedural tutorial
Fabian Schmengler's Blog: "Mocking" built-in functions like time() in Unit
by Chris Cornutt March 18, 2011 @ 08:52:03
In a recent post to his blog Fabian Schmengler looks at mocking something in your unit tests that could cause problems in certain situations - needing a specific kind of response from a built-in PHP function. In his case, he shows how to mock time to return the same formatted date.
A common problem in Unit Testing in PHP is testing something that depends on the current time. For a determined test it should be possible to set the time in your test script without really changing the system settings. In this article I'll describe how it is usually done with OOP and then come to an alternative solution with much less code that makes use of the new features in PHP 5.3.
He shows a usual approach using dependency injection and a class wrapper to handle the set and fetch of the date value. His alternative uses namespacing to redefine the internal PHP function into something custom. Then, when the test is executed, it can use that custom namespace's version, overriding the default. It's a pretty seamless option and can save you a good bit of time and hassle with other classes each time you need to customize the results.
voice your opinion now!
mock phpunit unittest time namespace
DZone.com: Date and time in PHP 5
by Chris Cornutt December 01, 2010 @ 13:58:03
New on the Web Builder Zone today, there's an article about DateTime in PHP5 from Giorgio Sironi introducing you to this very handy built-in feature.
PHP has made some progress here as well, for example with the Standard Php Library and its interfaces. Though, the SPL is incomplete and oriented to performance more than to object-oriented programming: take a look at the SplStack and SplQueue implementation containing 20 different methods to get the idea. However a little gem is shipped with each PHP installation: the datetime extension, which contains the DateTime class and its siblings. Ideally, everything you can do with date_* functions, you can do it with this class.
He includes some code that shows the DateTime object in action as a part of a PHPUnit test case - adding days, subtracting months, date difference and its support of operator overloading. There's also mention of Doctrine's native support for the extension.
voice your opinion now!
datetime date time tutorial introduction
Till Klampaeckel's Blog: APC get a key's expiration time
by Chris Cornutt November 11, 2010 @ 11:28:55
Till Klampaeckel has shown off one of the "best kept secrets" about the APC caching tool that not many people seem to use - getting a key's expiration time that can be useful to tell other applications how long the data will be good for.
APC offers a bunch of very useful features - foremost a realpath cache and an opcode cache. However, my favorite is neither: it's being able to cache data in shared memory. How so? Simple: use apc_store() and apc_fetch() to persist data between requests. The other day, I wanted use a key's expiration date to send the appropriate headers (Expires and Last-Modified) to the client, but it didn't seem like APC supports this out of the box yet.
He includes a quick bit of sample code that defines an "apc_exire" function that grabs the expiration information as returned by apc_cache_info - the "ttl" and "creation_time" values.
voice your opinion now!
apc cache expiration time
Brandon Savage's Blog: The Fallacy of Sunk Cost
by Chris Cornutt May 11, 2010 @ 09:35:28
Brandon Savage has a new post about something that some developers out there factor into their development estimates from the beginning and others are just learning how to adjust to - the sunk cost that can be associated with writing code.
Last week, I began working on something that didn't pan out. For whatever reason, I went down the wrong path, and ultimately abandoned the task I was working on. In discussing it with my boss, he mentioned to me that it was better to realize early on that something wouldn't work than to trudge onward, insisting that it be finished due to the "sunk cost" of the time already spent.
There's two sides to this story - one in which the application continues to be developed and takes up more time (but still ends up as a product) and the other where the time already spent is lost as a completely new approach is taken.
voice your opinion now!
sunk cost development time decision
Ibuildings techPortal: Tips for PHP Date and Time Functions
by Chris Cornutt January 26, 2010 @ 10:06:57
In this new post from the Ibuildings techPortal today Michael shares some handy tips for working the date and time functions in PHP (all can be used in a non-PHP 5.3 installation).
His tips for these very handy functions include:
- A Unix timestamp is never timezone-specific; if you call time() at the same moment on computers in different time zones, you get exactly the same value back.
- The time string is interpreted as a local time; there is no gm- equivalent [of strptime], or even any way to simulate one, since it ignores the value of date_default_timezone_set. Note that you can impose a timezone on the input string if it contains a timezone abbreviation or offset.
- [With date/gmdate] as with strftime/gmstrftime, the gm- prefix affects whether the result is a representation of the time in the current timezone or in the UTC timezone.
- How does PHP know what your current timezone is? It tries a few different places, including the TZ environment variable and the date.timezone ini option.
voice your opinion now!
date time tip feature
PHPFreaks.com: Working with dates in PHP
by Chris Cornutt August 20, 2009 @ 11:38:51
On PHPFreaks.com today there's a new tutorial looking at working with dates and times in PHP. This includes timezone support and date manipulation.
There are many topics on the forums that go again, topics many people often are having trouble with. One of these problem areas are how to handle dates, convert them to a different format, timezone issues, etc. This tutorial will attempt to address many of the commonest problems related to date and time issues.
Besides looking at some of the common date/time issues that developers might face, they also touch briefly on storing dates in a database and offer some recommendations as to a few best practices to help keep things straight.
voice your opinion now!
date time tutorial database
|
Community Events
Don't see your event here? Let us know!
|