PHP, the programming language that has been declared dead more times than a cat has lives, is still very much alive and kicking. Despite what some elitist developers may say, PHP is not going anywhere anytime soon.
Despite all the naysayers constantly predicting its demise, PHP continues to chug along, powering some of the biggest websites on the internet.
Let’s start by taking a look at the statistics. According to W3Techs, PHP is currently used by 78.9% of all websites with a known server-side programming language. That’s a pretty impressive number, considering that PHP has been around since 1995. To put it in perspective, that’s longer than some developers have been alive. And the reason why it has been around for so long is that it just keeps getting better.
This is another of those particular posts that might help one or two people out. If I can save you some time working with the News Industry Text Format in PHP, I’ll be glad that you didn’t experience my frustration.
While working with the Associated Press API, I recently ran into a situation where ingested content from the NITF format they supply was being stripped out in PHP.
The code in question looked like this:
Filed under: super-specific use case with hints of generality for those wanting to write long-running PHP scripts.
For a little while now, I have been building a site with WordPress that consumes news content from the Associated Press news API and then stores the news content in WordPress.
My first iteration of the ingest engine with PHP worked quite well, but I encountered dreaded NGINX server timeouts and other issues.
Recently I was tasked with processing some content from an API, the published dates and times were coming through with timezone values in the string. My dates looked like this: 2021-09-29T04:24:39Z
If you parse these using strtotime like I was and importing them into WordPress, even if your server timezone is configured correctly, the timezone will be wrong. In my situation, the dates and times were showing all hours of the morning.
I have been working on a WordPress site that parses remote news API’s and requires not only parsing the news format JSON but getting any associated media and downloading them.
Herein lies the problem: the download_url function that WordPress provides does not support passing in headers. If you are working with a remote API that requires passing an authorization header, then this function won’t work.
Unbbeknownst to some, the underlying download_url function uses WordPress request methods to make the request for the file. Taking the original function from the codebase and making some simple tweaks, we end up with something like this.
Recently I encountered a dreaded issue whilst trying to install Laravel on my Mac OSX machine.
The message I was getting was:
Allowed memory size of 536870912 bytes exhausted (tried to allocate 72 bytes) in phar:///usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php on line 123
The issue was perplexing according to PHP I had allocated 128mb of memory for PHP, but apparently this wasn’t enough. It appears as though dependencies are managed within memory and all of the components that make up Laravel (mostly Symfony) take up more than 128mb of memory.
This is an interesting question I have been asked about a few times now and it appears many developers are confused what the answer is. Long story short: Yes, you should commit your composer.lock file.
The composer.lock file is a build metadata file that specifies exact versions of dependencies in your Composer project. It means if someone else in the team pulls down your code, they will get the exact same versions specified.
Laravel is undoubtedly one of the best things to happen to PHP and you’ve probably guessed based on my post history, I really like it and want to expose more people to its cool features and help the PHP ecosystem move away from the stigma of all PHP code being bad.
Today, in this tutorial like post I will be explaining how you can add in a user following system like Twitter, Quora or any other social network that allows you to follow another user and have users follow you.