how to store data in cache file in php

welcome back to shortlearner.com, in this post we will see how to store data in cache file with the help of PHP.
before start this tutorial we should take an overview about cache.
so the very first question in our mind is what is cache , why we store our data in cache file, and what are the benefits to store data in this file.

data caching in php

so basically data caching refers to storing the result of an operation into a file so that future request return faster or we can say that caching is a perfect way to showing repeated data with minimum execution time.

Also Read
How to Install PHP on CentOS.
How to Send Attachment on mail using PHP.

PHP Login Script With Remember me.
Unable to create a directory a wordpress error

How to integrate Razorpay Payment Gateway using PHP.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

in the below code we are creating a cache file with the help of php script and store data into that file and match the execution time of both actions.

so i have a table in MySQL database with the name of cities and this table have thousands of record in it. so whenever i use select query to fetch all records from the database it takes some time to execution which is more than 5 seconds. i want to reduce this execution time from 5 seconds to 0.005 seconds.

here i am using microtime() which is store the time before the script is start for execution. than we declare a variable of $cache_file and check that the file is exist or not.

so in the very first time this is not exist so we fetch all records from database and store in our $cache_file by using predefined file functions.
now when we perform the same task again it will fetch records from our $cache_file file which will exist this time.

and after the end we store execution time again in our $end variable and than check the difference between start and end time of execution so we got the actual execution time of this script.

how to get data from api using curl in php

Welcome back to shortlearner.com, In this post we will see how to fetch record from a website by using cURL API. so before start this tutorial we should take an small overview of it, what is it , how does it works and its benefites.

PHP cURL tutorial

What is cURL

so basically cURL means client URL which allows us to connect with other URLs and use their responses in our code, and it is a library that allows to make HTTP requests in PHP.
in order to use PHP’s cURL functions we need to install the libcurl package in our server.
PHP also requires that we use libcurl 7.02-beta and higher and it is works from PHP version 4.3.0 or higher.
in easy way cURL is a way to hit an URL from our code to get a html response from it.

Also Read
How to Install PHP on CentOS.
How to Send Attachment on mail using PHP.

PHP Login Script With Remember me.
Unable to create a directory a wordpress error

How to integrate Razorpay Payment Gateway using PHP.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Now we understand the uses of cURL with a real life example. suppose you are a owner of 5 luxuries hotel and all are registered in some kind of OTA (online traveling agent) like make my trip, goibibo and travel guru.
you want to manage all the inventory and rates on their platforms according to season.

in this case you have perform this task in 2 ways. first and difficult one is you go to each and every OTA’s dashboard and manage inventory or rates or you can try to develop a platform to manage all the hotels by using API.

so if you have a knowledge of cURL funcationlity you will manage it easily by hitting client’s URL.

In the below code we fetch the record from jsonplaceholder.typicode.com/users by using cURL functionality and print it on our webpage.

first of all we use curl_init() function, this function is use for initializes a new session.
curl_setopt() functions is ues for set URL.
CURLOPT_RETURNTRANSFER that will return the transfer as a string of the return value of curl_exec().
and curl_close() that is using for end the session.

how to create social media share buttons

In this post we learn how to create social media share buttons with the help of font awesome icons , bootstrap and CSS and learn how to deploy it for any website.


so before start this tutorial we should take an small overview about fontawesome and learn the implementation process of icons.

we are living in the era of digital. we have a lots of digital platform like facebook, twitter, instagram, linkedin, whatsapp, google plus and many more.

Today most of the business and companies are holding their social account. so they can reach to their customers or client base via sharing some important and relatable contents according to their niche, and sharing all the offers and information over there.

most of the developers are uses small images of social media platform or uses favicons of also .fontawesome and glyphicons are the two third party icon providers which have a good library of favicons and easy to implement.

If we want to share this article with different type of social media platforms so this article with reach more readers than i use this .

In the below code we will learn how to add share button to website. so just copy the code and paste it to your website.

now we are adding some CSS to creating our button responsive and attractive. just copy the below CSS part and paste it in the head section of your html code.

this is the customization of social network sharing buttons. if you are trying to add on WordPress website than there are some best plugins that will help you.

WordPress to Buffer
Simple Social Icons
Social Icons Widget by WPZoom
WordPress Social Login
Revive Old Posts
AddtoAny

hope this article will helps you. please share this article with all your developer buddies and help them.

How to extract all URL from website in PHP

Welcome to another PHP tutorial post. in our previous post we learn how to Get Domain Name from URL in PHP
today in this post we will learn how to extract all URL from a website with the help of predefined PHP functions like file_get_contents.

extract all url using php

so before start to fetching all URL of a website or a webpage we will take an short overview of DOMDocument.

What is DOMDocument in PHP

The PHP DOMDocument library allows us to manage HTML and XML pages after uploading our script in new DOMDocument.
so basically it is a best option to reading and changing into a HTML and XML files with the help of DOM library.

file_get_contents for reading

as we all know that file_get_contents is a predefined PHP functions which is helpful for read a content of a file into a string format.
So first of all we are creating a variable with the name of $html which will store all the string values which will converted by file_get_contents functions of PHP.

after putting the values in $html variable we are simple create a new DOM document which will Parse the HTML. The @ is used to suppress any parsing errors, that will be thrown if the $html string isn’t valid HTML.

by using DOMDocument PHP function getElementsByTagName() we will get a new instance of class DOMNodeList which contains all the elements of local tag name.
so we are passing anchor tag in side getElementsByTagName().

so in the below code we are putting our URL to fetch all the links which are inside the anchor (a) tag.

Also Read
How to Install PHP on CentOS.

How to Send Attachment on mail using PHP.

PHP Login Script With Remember me.
Unable to create a directory a wordpress error

How to integrate Razorpay Payment Gateway using PHP.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

How to Generate Firebase Server Key

Welcome back to shortlearenr.com, in our previous post we learn how to implement Razorpay Payment gateway with the help of PHP.
today in this post we will see how to Generate Firebase Server Key.
so before start this tutorial we will take an short overview about firebase and its uses.

FCM push notification for android

What is Firebase

so basically Firebase is a tool which is developed by google, to building app infrastructure and improving app quality for growing your business.

so Firebase server key is used to send push notifications to android devices and this server API key is used to identify Firebase application.
we are generating Firebase server key in the below steps, keep follow the steps

Create a Firebase project and Get your Server Key

Step1 : In the very first step we have to log in into Firebase Developer Console. if you still not created any project simply click on Create project.

firebase server key

Step2 : Enter your project name, accept the Firebase terms and conditions and hit the CREATE PROJECT button.

firebase development

Also Read
How to Install PHP on CentOS.
Unable to create a directory a wordpress error
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript

How to integrate Razorpay Payment Gateway using PHP.
Check Email is Already Registered in Database using Ajax and JavaScript.
How to hide extension of html and php file.?

Step3 : In the third step we select Not right now option because we will setup our google analytics later and hit create project button.

firebase cloud messaging for android and php

Step4 : After hitting the create project button we will get a message Your new project is ready, press the Continue button to redirect your project dashboard page.

firebase cloud integration using php

Step5 : On the dashboard page click on the Gear icon which is in the top left and select Project settings.

FCM integration in php

Step6 : In the last step we just click on the Cloud Messaging Section and we will have the Server Key.

get FCM server key

thanks for reading, if this article helps you please support us and share with your developer buddies.