Bootstrap 3 Navbar with Logo Image

The correct way to use a logo image on the Navbar on Bootstrap 3 is: <a href="#" class="navbar-left"><img src="/path/to/image.png"></a><a href="#" class="navbar-left"><img src="/path/to/image.png"></a> Do not use class=”navbar-brand” in A HREF because it adds text-like styles. Reference: If the logo image is too on top, just add this code in the .CSS file: .navbar-default .navbar-left img […]


Today I tested HMGET, HGETALL, HSET, HGET performance. Here are my tests, see the “requests per second” value for comparisons: TESTING GET COMMAND     root@server:~# redis-benchmark -h -p 6379 –dbnum 1 get MYKEY ====== get MYKEY ====== 100000 requests completed in 3.27 seconds 50 parallel clients 3 bytes payload keep alive: 1   […]

PHP GetHostByName() Slow? Make it Faster

Sometimes gethostbyname() can take up to 5 seconds and more to complete. Here are two smart tricks to make it faster: // Set timeout and retries to 1 to have a max execution time of 1 second for the DNS lookup putenv(‘RES_OPTIONS=retrans:1 retry:1 timeout:1 attempts:1’);   // Make sure the domain ends in a dot […]

Use Timestamp with new DateTime() in PHP

You can use a unix timestamp within DateTime() like this: $today = new DateTime("@".time()); $tomorrow = new DateTime("@".strtotime("+13 months"));$today = new DateTime("@".time()); $tomorrow = new DateTime("@".strtotime("+13 months")); See that we prepend “@” char before the timestamp.

Calculate Elapsed Time Between Two Dates in PHP

This function is used to calculate elapsed time between two dates: function formatDateDiff($start, $end=null, $ago=" ago", $left=" left") { if(!($start instanceof DateTime)) { $start = new DateTime($start); }   if($end === null) { $end = new DateTime(); }   if(!($end instanceof DateTime)) { $end = new DateTime($start); }   $interval = $end->diff($start);   $elapsedtype = […]

PHP Display Date Same as Server HTTP Headers Date

Display date same as server’s HTTP Headers date: $date = gmdate(‘D, d M Y H:i:s T’, time());$date = gmdate(‘D, d M Y H:i:s T’, time()); Example output: Tue, 29 Jan 2019 13:23:38 GMTTue, 29 Jan 2019 13:23:38 GMT

Google Cloud Load Balancer Firewall Rules

If you need to create firewall rules related to Google Load Balancer: You must create a firewall rule that allows traffic from and to reach your instances. This rule allows traffic from both the load balancer and the health checker. The rule must allow traffic on the port your global forwarding rule has […]

Create Instance Template out of Disk Snapshot on Google Cloud

You can create an Instance Template out of disk snapshot like this: 1) Created an instance 2) Install the required services on that instance 3) Create the image from the disk using the steps mentioned on this link. 4) With that Image create a new template. Other simpler steps recommended by an user: 1) Create […]

Get User IP Address From Google Cloud Load Balancer

Google Cloud Load Balancer saves the user’s IP in the X-Forwarded-For field: X-Forwarded-For: -client IP(s)-, -global forwarding rule external IP-X-Forwarded-For: -client IP(s)-, -global forwarding rule external IP- More information can be found here: Here is a sample PHP snippet to get the user’s IP address: $user_ip = explode(",", $_SERVER[‘HTTP_X_FORWARDED_FOR’])[0]; print_r($user_ip);$user_ip = explode(",", $_SERVER[‘HTTP_X_FORWARDED_FOR’])[0]; print_r($user_ip);

Connect as Root using WinSCP on Google Cloud Compute Engine

To connect as root with your Compute Engine VM using WinSCP do this: Option 1: Using Session -> File Protocol -> SCP sudo su -sudo su – Option 2: Using Session -> File Protocol -> SFTP sudo -s /usr/lib/sftp-serversudo -s /usr/lib/sftp-server