Today I eventually started optimizing the performance (thereby reducing server load a bit). It appeared some pages of my larger websites have grown to round about 300 kb causing some latency for lower bandwidth visitor. Having a quite good connection myself, I didn't care about that much in the past. But that's ab pity, because it is very simple to add compression to pure PHP-generated content.
Handling date and time in PHP makes most coders nervous. There are a bunch of functions playing arround with system time and timezone features, using UNIX timestamps and therefore are very limitted in application. At least I know a lot of guys born before 1970. Native Unix timestamps may be of great use for system level stuff like logging information or handling object lifetime, but not for real world scenarios: handling user age or historical events is impossible with 32 bit UNIX timestamps.
PHP from version 5 on provides reasonable object support. Well the language is not really object-oriented, but hey, it's a scripting language!
Recently I had the chance to implement the proxy pattern (one of my favourite design patterns) in PHP. My goal was to make object relations more dynamical. Lets start from a simple assumption of two kinds of objects:
class Parent { var $ID; var $Child; } class Child { var $ID; var $Parent; }
As you'll notice, both classes reference each other. Parent points at Child and Child points to Parent.
PHP might be the most often used Internet programming language. One reason might be it's so simple and docile even a beginner without much experience can use it.
When a website becomes older and mature, and starts to attract more people a day, many webmasters face a new competition: keep the scripts running, performing good enough to be usable to their visitors. This is the time where one has to think about performance-tuning PHP. One way to achieve better performance is, to plug in better hardware. Another way (the one we choose for this article) is to fine-tune the software side at PHP level.
Pattern matching using "*" and "?" wildcards is the common approach under Windows when it comes to comparing paths. Many applications - lead by DOS, cmd.exe and explorer.exe (the Windows Explorer) - allow users to use wildcards in paths. Users thereby are enabled to select a group of files matching specific criteria, which is often used in the "open document" dialog of Windows applications.
Matching a string agains a pattern is a very simple thing if you've got a framework or interpreted high level language like PHP or C# (or any of the .NET Framework languages). Those languages already provide classes or functions for using Regular Expressions (RegEx) and thus allow for very complex string comparison, string matching and string replacement features out of the box.
The same topic can become rather complicated when you're (for what reason ever) are limited to pure C and don't want or just can't include complex classes. As I had the same problem and luckily solved it, I decided to provide you the surprisingly very simple C code for matching a string against a pattern containing wildcard if you like.