Saturday, December 21

PHP

PHP

Cannot Compose an Essay – How to Create an Essay

Cannot Compose an Essay - How to Create an EssayDid you know you can't ever write an informative article in a straight line? That sounds ridiculous, doesn't it? Well, it is true. You can not compose an essay in a straight line, but it's still possible to find an excellent essay.First of all, exactly what exactly are you going to come up with? Probably something which you are enthusiastic about, or something that you have a particular curiosity about. What about it have you tried to create before? For those who have written a book, or even a magazine article, you are probably knowledgeable about the kind of sentences that you need to create. For those who haven't written some thing similar to that before, you may be wondering if you are likely to think of a few thoughts.The issue wit...
PHP, Web Tricks

How to redirect http to https in wordpress using htaccess

Today I faced a very simple issue and I am going to share that with all of you. In general when we move our wordpress site from Http to Https then we simple change urls in Wordpress->Settings->General. But still if any user is going to open your site with http then it will show in http and that's very bad for you site ranking. For an example my site is on SSL and url is as below: https://phpinfo.in Now when you will try to open below urls then you won't redirect on https automatically http://phpinfo.in phpinfo.in If https:// is not in the prefix, the HTTP link loads instead. To overcome this issue you just need to add the following into your .htaccess in between the tag: RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] If there were no add...
PHP, Web Tricks

Show/Hide button on window scrolling

Today I worked on this for one of my client so I thought I should share this with all of you. My client wanted me to show a fixed button in the right side of his website and it should only show on scrolling between particular area. I've coded according to requirements and I am going to share jQuery code for the same. Code is as below: (I am expecting that you already have jquery library in your code.) <script> jQuery(document).ready(function(e) { var topScrollpos = 360; var bottomScrollpos = 1820; window.onscroll = function() { var currentScrollPos = window.pageYOffset; if (currentScrollPos > topScrollpos && currentScrollPos < bottomScrollpos) { jQuery("#float-button").css('display','block'); } else { jQuery("#float-button").css('display','none'); } } })...
PHP

How to Install PHP on Windows

We've previously shown you how to get a working local installation of Apache on your Windows PC. In this article, we'll show how to install PHP 5 as an Apache 2.2 module. Why PHP? PHP remains the most widespread and popular server-side programming language on the web. It is installed by most web hosts, has a simple learning curve, close ties with the MySQL database, and an excellent collection of libraries to cut your development time. PHP may not be perfect, but it should certainly be considered for your next web application. Both Yahoo and Facebook use it with great success. Why Install PHP Locally? Installing PHP on your development PC allows you to safely create and test a web application without affecting the data or systems on your live website. This article describes PHP install...
PHP, Web Tricks

WordPress Notifications Made Easy

WordPress doesn’t offer any kind of notification system. All you can use is the wp_mail() function, but all of the settings have to be hardcoded, or else you have to create a separate settings screen to allow the user tweak the options. It takes many hours to write a system that is reliable, configurable and easy to use. But not anymore. I’ll show you how to create your own notification system within minutes with the free Notification plugin. By notification, I mean any kind of notification. Most of the time, it will be email, but with the plugin we’ll be using, you can also send webhooks and other kinds of notifications. While creating a project for one of my clients, I encountered this problem I’ve described. The requirement was to have multiple custom email alerts with configurable c...
Improving Performance Perception: On-demand Image Resizing
PHP

Improving Performance Perception: On-demand Image Resizing

Over a series of articles, we've been building a sample application --- a multi-image gallery blog --- for performance benchmarking and optimizations. At this point, our application serves the same image regardless of the resolution and screen size it's being served in. In this tutorial, we'll modify it to serve a resized version depending on display size. Objective There are two stages to this improvement. We need to make all images responsive wherever this might be useful. One place is the thumbnails on the home page and in the gallery pages, and another is the full-size image when an individual image is clicked in the gallery. We need to add resizing-logic to our app. The point is to generate a resized image on the fly as it's demanded. This will keep non-popular images from polluting o...
How to Boost Your Server Performance with Varnish
PHP

How to Boost Your Server Performance with Varnish

Varnish Cache is an HTTP accelerator and reverse proxy developed by Danish consultant and FreeBSD core developer Poul-Henning Kamp, along with other developers at Norwegian Linpro AS. It was released in 2006. According to Pingdom.com, a company focused on web performance, in 2012 Varnish was already famous among the world's top websites for its capacity to speed up web delivery, and it was being used by sites such as Wired, SlideShare, Zappos, SoundCloud, Weather.com, Business Insider, Answers.com, Urban Dictionary, MacRumors, DynDNS, OpenDNS, Lonely Planet, Technorati, ThinkGeek and Economist.com. It is licensed under a two-clause BSD license. Varnish has a premium tier, Varnish Plus, focused on enterprise customers, which offers some extra features, modules, and support. Although there a...
Optimization Auditing: A Deep Dive into Chrome’s Dev Console
PHP

Optimization Auditing: A Deep Dive into Chrome’s Dev Console

Chrome DevTools incorporates many sub-tools for debugging web applications on the client side --- like recording performance profiles and inspecting animations --- most of which you've likely been using since your early days of learning web development, mostly through the DevTools console. Let's look at some of those tools, focusing particularly on the console and the performance metrics. To access Chrome's DevTools: right click anywhere on a page, click Inspect from the context menu use the keyboard shortcuts Ctrl + Shift + I on Windows and Linux systems or Alt + Command + I on macOS use the keyboard shortcuts Ctrl + Shift + J on Windows and Linux systems or Alt + Command + J on macOS. The Snippets Tool If you're frequently writing JavaScript code right in the console, make sure to use th...
PHP

Improving Page Load Performance: Pingdom, YSlow and GTmetrix

Optimizing websites for speed is a craft, and each craft requires tools. The most-used website optimization tools are GTmetrix, YSlow and Pingdom Tools. GTmetrix is a rather advanced tool that offers a lot on its free tier, but it also offers premium tiers. If you sign up, you can compare multiple websites, multiple versions of the same website, tested under different conditions, and save tests for later viewing. YSlow is still relevant, although its best days were those when Firebug ruled supreme among the browser inspectors. It offers a Chrome app and other implementations --- such as add-ons for Safari and Opera, a bookmarklet, an extension for PhantomJS, and so on. For advanced users, PhantomJS integration means that one could, for example, automate the testing of many websites --- hun...
How to Use Varnish and Cloudflare for Maximum Caching
PHP

How to Use Varnish and Cloudflare for Maximum Caching

This article is part of a series on building a sample application --- a multi-image gallery blog --- for performance benchmarking and optimizations. (View the repo here.) As we can see in this report, our site's landing page loads very quickly and generally scores well, but it could use another layer of caching and even a CDN to really do well. To learn more about GTMetrix and other tools you can use to measure and debug performance, see Improving Page Load Performance: Pingdom, YSlow and GTmetrix Let's use what we've learned in our previous Varnish post, along with the knowledge gained in the Intro to CDN and Cloudflare posts to really tune up our server's content delivery now. Varnish Varnish was created solely for the purpose of being a type of super-cache in front of a regular server. ...
Server-side Optimization with Nginx and pm-static
PHP

Server-side Optimization with Nginx and pm-static

This article is part of a series on building a sample application --- a multi-image gallery blog --- for performance benchmarking and optimizations. (View the repo here.) Let's continue optimizing our app. We're starting with on-the-fly thumbnail generation that takes 28 seconds per request, depending on the platform running your demo app (in my case it was a slow filesystem integration between host OS and Vagrant), and bring it down to a pretty acceptable 0.7 seconds. Admittedly, this 28 seconds should only happen on initial load. After the tuning, we were able to achieve production-ready times: Troubleshooting It is assumed that you've gone through the bootstrapping process and have the app running on your machine --- either virtual or real. Note: if you're hosting the Homestead Improv...
Using Background Processing to Speed Up Page Load Times
PHP

Using Background Processing to Speed Up Page Load Times

This article is part of a series on building a sample application --- a multi-image gallery blog --- for performance benchmarking and optimizations. (View the repo here.) In a previous article, we've added on-demand image resizing. Images are resized on the first request and cached for later use. By doing this, we've added some overhead to the first load; the system has to render thumbnails on the fly and is "blocking" the first user's page render until image rendering is done. The optimized approach would be to render thumbnails after a gallery is created. You may be thinking, "Okay, but we'll then block the user who is creating the gallery?" Not only would it be a bad user experience, but it also isn't a scalable solution. The user would get confused about long loading times or, even wor...
Improving Performance Perception with Pingdom and GTmetrix
PHP

Improving Performance Perception with Pingdom and GTmetrix

This article is part of a series on building a sample application --- a multi-image gallery blog --- for performance benchmarking and optimizations. (View the repo here.) In this article, we'll analyze our gallery application using the tools we explained in the previous guide, and we'll look at possible ways to further improve its performance. As per the previous post, please set up Ngrok and pipe to the locally hosted app through it, or host the app on a demo server of your own. This static URL will enable us to test our app with external tools like GTmetrix and Pingdom Tools. We went and scanned our website with GTmetrix to see how we can improve it. We see that results, albeit not catastrophically bad, still have room for improvement. The first tab --- PageSpeed --- contains a list of ...
PHP

MySQL Performance Boosting with Indexes and Explain

Techniques to improve application performance can come from a lot of different places, but normally the first thing we look at --- the most common bottleneck --- is the database. Can it be improved? How can we measure and understand what needs and can be improved? One very simple yet very useful tool is query profiling. Enabling profiling is a simple way to get a more accurate time estimate of running a query. This is a two-step process. First, we have to enable profiling. Then, we call show profiles to actually get the query running time. Let's imagine we have the following insert in our database (and let's assume User 1 and Gallery 1 are already created): INSERT INTO `homestead`.`images` (`id`, `gallery_id`, `original_filename`, `filename`, `description`) VALUES (1, 1, 'me.jpg', 'm...
PHP-level Performance Optimization with Blackfire
PHP

PHP-level Performance Optimization with Blackfire

Throughout the past few months, we've introduced Blackfire and ways in which it can be used to detect application performance bottlenecks. In this post, we'll apply it to our freshly started project to try and find the low-points and low-hanging fruit which we can pick to improve our app's performance. If you're using Homestead Improved (and you should be), Blackfire is already installed. Blackfire should only ever be installed in development, not in production, so it's fine to only have it there. Note: Blackfire can be installed in production, as it doesn't really trigger for users unless they manually initiate it with the installed Blackfire extension. However, it's worth noting that defining profile triggers on certain actions or users that don't need the extension will incur a performa...