Tag: PHP
-
How to write files to disk with PHP
Saving files to disk is a pretty simple task in PHP with file_put_contents(). Here’s how to write a string to a file: $string = ‘I AM STRING!!’; file_put_contents(‘/path/to/destination’, $string); It is generally good practice to only do with when you are dealing with smaller strings as you can run into…
-
How to use try/catch statements in PHP. Oh, and finally too!
I do a lot of coding in Python and one thing that I really love is the mindset of asking for forgiveness instead of permission. What’s this mean? It means that instead of sanity checking every little thing, just handling the exceptions that are thrown instead. In PHP this can…
-
How to use switch/case statements in PHP
switch/case statements are one of my favorite anti-patterns not because I prefer to write spaghetti code but because they can make if/elseif blocks look a ton cleaner. Why would it be considered an anti-pattern? Because it could easily be abused to the point that you are munging up your control…
-
Your stack is outdated
I’ve been noticing a pattern with most of my peers (yes I said most), they expect their users to be running the latest and greatest version of their favorite “modern” browser and all the while their server stack is collecting dust. Ubuntu doesn’t help matters with their Long Term Service…
-
Improve performance by reusing PHP objects
I’ve been doing a ton of optimizations on one of my main sites and one thing that I’ve been doing more and more is trying to reuse objects whenever possible. What’s this entail? All it takes is creating a static function to return an instance of the object instead of…
-
How I saw the test-driven light
Aside from dealing with financial transactions, I’ve generally avoided test-driven development as part of my day to day workflow. Why? The usual reasons, but mostly because I didn’t want to incur the overhead of additional development. As a single founder / developer you’re always looking for ways to lighten the…
-
PHP 5.5 syntax highlighting for Vim
Now that I’m using PHP 5.5 I’m finding that my Vim syntax highlighting is a bit off. After some digging around I found a syntax file that was updated to PHP 5.5 RC1 but hasn’t been updated since. In true hacker fashion I went ahead and forked the project and…
-
Upgrade from PHP 5.3 to PHP 5.5 on Ubuntu 12.04 LTS
Recently I made the decision to stop living in the past and start living in the present by using the latest stable release of PHP, version 5.5.8. Unfortunately on Ubuntu 12.04 LTS (I always run LTS releases on my servers) the latest version of PHP available is from the 5.3…
-
PHP segmentation faulting from logging too much
At least I think that’s what was happening. Today I made the somewhat calculated risk of upgrading my production server from PHP 5.3.10 to PHP 5.5.7. Scary stuff, jumping 2 point revisions like that but I was feeling cocky after jumping 3 point revisions to bring nginx up to the…
-
Getting PHP’s version from the command-line
As you may already know, obtaining the version number of PHP is a simple php –version away. This is great if you just want to see the version number, but what if you wanted just the version number? First option would be to use write out some shell script to…