Supercharge WP REST API with Google App Engine

It seems that I am pretty late here to play with WordPress REST API. It’s really super cool! Now I can think about how well and fast I can distribute or work with wordpress blog posts. Even now you can host your whole WordPress inside a static HTML page. Funny? Yea, like your HTML page will interact with your REST API json response and small JS can help you to display inside page. Then you will get 10000000x super fast blog post delivery. Trust me! It works. You will understand if you are a little techie guy.

I was thinking about if I can easily get all of my posts’s data as REST API Json response then easily I can use them wherever and whenever I want. But there must be a trick. Cause still this REST API is working from inside your main WP hosting.

But what if (IF) we can recruit some middleman who can hold data and deliver those data without even interacting with your original WordPress site. So you will save lots of money and your site’s performance will be super boosted.

I just run an experiment (I shared my experimented snippet here) with Google App Engine. Why Google App Engine? Ask that to google yourself. Google App Engine is the best solutions for ready-set-go types of app deployment with lots of features that Google maintains themselves. So I am going to write a small PHP code which will load your site’s REST API JSON data and after that rest of the request it will server from directly GAE memcache. So, more easily, if your site has 1M audience a day, then most probably you will hit your original WP site once, and 999999 user will get that data from directly App Engine (PHP app data persistent through memcache).

I just tried it and it works and I tried to do 50,000 hits and it just took few milliseconds to deliver me my wordpress site’s data from Google App Engine and I just designed a HTML page with simple JS that will load the content from my App Engine and will display inside HTML page, and you know HTML page you can serve billions user in a minute. Voila 🙂

So here is my little PHP script and also I uploaded the full GAE implementation in a GitHub repository so you can directly download, change your site’s URL and deploy to Google App Engine.

And here is the app.yaml configuration for Google App Engine

This snippets are available on GitHub. If you face any trouble and want to optimize your site and make it super-fast and stable with this types of solutions, reach me anytime at shaharia@previewtechs.com

Slim PHP Framework PhpStorm IDE autocompletion Solution

Slim PHP Framework PhpStorm IDE autocompletion Solution

I am a big fan of PHP Slim Framework. But sometimes, I realized that when I work with large and complex libraries with Slim as dependency. It just kills my productivity, it kills my valuable time too. It’s all because of I can’t remember all the method names, properties of my dependent class or libraries. And with Pimple dependencies Slim Framework don’t have any way to bypass referencing of my third party libraries which I add through it’s container as dependency. So I decided to figure out a solution for me.

First, I just installed and configured slim framework and here is my scripts.

 

And I created a class HintsClass. Now the main trick is, I created a dummy _ide_autocomplete.php file in the project root and defined all the containers key as public property. Like this.

 

Now our goal is from inside route, our PHPStorm IDE will show the autocomplete and hinting for code completion when we will access this class with $this->hints->[ctrl+space to see autocompletion]. And in our _ide_autocomplete.php file we wrote the following codes. FYI, this _ide_autocomplete.php will never execute. It just used for giving IDE as a referential hinting for all the properties .

 

You will see in this Dummy class file according to our slim containers[‘hints’], I just mentioned the same return reference here. And see my main index.php, in every route I just gave IDE hints about the $this context with

And after that from route context IDE will show the autocompletion of our dependencies like $this->hints[ctrl+space to see suggestions].

You can see my whole scripts are in GitHub https://github.com/shahariaazam/slim-phpstorm-autocomplete. And see this work in YouTube, https://www.youtube.com/watch?v=jyEvApLRofw .Please let me know if any issue found, write me in comments. Thank you.

Get ThemeForest theme information and stats with simple PHP script

Now a days, lots of professionals are selling their creative works on ThemeForest. I just created the following simple (very simple) PHP script that works with HTML DOM and XPATH will do a very interesting job to show the ThemeForest theme information and statistics.

Just run this script on your PHP environment and you will get the following information of any specific ThemeForest theme.

 

WHMCS PHP API – Integrate billing system with your application

WHMCS is a popular billing system specially for domain+hosting business. It provides mostly billing solutions. You can download WHMCS from download page. As a billing system, if you have several tools, utilities and services that require connection between your application and WHMCS then you badly need API to accomplish that interconnection.

WHMCS has a very basic API documentation (it’s enough though) without any specific programming library. You can use the following wrapper class to interact with your WHMCS system from your PHP application. This is very simple and doesn’t require further explanation in depth. See the following script. If you have any better idea or suggestions, don’t forget to write me in the comment area.

Google Mobile-friendly test in PHP

Lots of folks out there about to make your website Mobile-friendly. It’s obvious that there will be significant impact on your website if your site is not mobile-friendly or what we regularly call ‘responsive’. Mobile friendly sites will get higher rank in search results in Google. And Google already started to rolling out this algorithms.

After searching on internet, I didn’t get any quick solution to check mobile-friendliness website in PHP. Although Google published it’s official Mobile-friendliness Test Tools.

When I tried to find some solutions then I figured out that Google has it’s public Pagespeed Test API v2. But in this version Google didn’t make it clear to see Pass or fail result for mobile-friendliness test. It only shows UX score. But in their v3beta1 API version they have a clear indicator about mobile-friendliness. And I figured it out and made a simple PHP functions to check the mobile-friendliness test of any website. Here is my scripts:

In the above script you just need to put your website URL to check and Google PageSpeed API Key what you will get from your Google API Console or see the Google PageSpeed Developer Getting Starter page.

Now, run your script and you will get the following array.

 

From the above array $result['ruleGroups']['USABILITY']['pass'] is the actual result of your website’s mobile-friendliness status. true means your website is mobile friendly and false means your failed to make your website mobile friendly. Simple.

Have fun! Write comments if you need any more assistance.