• Home
  • ZarxBiz
  • Forum
Igniter Code
IgniterCode.com === Zarx.Biz
ReactJS

ecommerce cart react source code 2022 [ For Beginners ]

October 8, 2022 0 comment

Why and how to use sql views 2022

August 22, 2022 0 comment

how to import csv to mysql using php

August 22, 2022 0 comment
PHP

Code faster using visual studio Updated 2022

July 31, 2022 0 comment

Web socket crash course 2022 updated step by step

July 3, 2022 0 comment

How to use stored procedure in sql updated 2022

September 3, 2022 0 comment
MySQL

Must know mysql functions updated 2022

September 3, 2022 0 comment

PHP Composer Autoload Complete Guide 2022

August 13, 2022 0 comment
Category:

PHP

how to import csv to mysql using php
MySQLPHP

how to import csv to mysql using php

by Manu August 22, 2022
written by Manu

Hi devs, In this guide we are going to see how to import millions of rows of data into database from csv file. This might take some time but for doing this we are going to process data using chunk method. So mainly we will process chunk of data and insert it into database and same process repeating again and again.

On we will follow these steps to import data

  1. Breaking large csv to smaller csv’s.
  2. reading smaller csv’s and store in database table.
  3. Each query will insert 1000 rows of data. (Max allowed in single query so).

Download the code zip if you wan it also check the video guide for practical usage.

In video guide we are also verifying if the all data inserted correctly or not.

Download Fileshttps://zarx.biz/topic/333/import-data-from-csv-file-to-database-in-php-import-millions-rows

August 22, 2022 0 comment
0 FacebookTwitterPinterestEmail
php application performance monitoring 2022
PHP

php application performance monitoring 2022

by Manu August 6, 2022
written by Manu

Php is one of the most famous language these days. Php rules the web. But it is important to have your PHP code clean and monitored so you get best out of PHP application.

In this guide we are going to take about 2 things.

  1. Monitoring Performance.
  2. Execution time.

For monitoring performance we can use these functions.

memory_get_usage and memory_get_peak_usage functions.

Memory Usage in PHP

memory_get_usage: This function will show us memory used for php while executing script.

memory_get_peak_usage: This function returns maximum memory used in script.
You can call these functions to see memory usage and then can modify your code to improve performance.

Execution Time in PHP

For checking execution time we have a function just add it on start of script and end of script and it will show you the execution time for both points

 

$startExecutionTime = getExecutionTime();
$endExecutionTime = getExecutionTime();

/**
 * GEt script start and end time.
 *
 * @return void
 */
function getExecutionTime()
{
    return microtime(true);
}

/**
/**
 * Get script execution time.
 */
function getProcessTime($startExecutionTime, $endExecutionTime)
{
    $diff = $endExecutionTime - $startExecutionTime;


    return 'Time taken to process code: '. date("H:i:s", $diff);
}

Note in above code we are passing $startExecutionTime.

Now to get start time put “$startExecutionTime = getExecutionTime” at start of your script and

put “$endExecutionTime = getExecutionTime” at the end of your script. Check our video guide for practical visual execution.

Download Files

August 6, 2022 0 comment
0 FacebookTwitterPinterestEmail
Improve productivity using visual studio a detailed guide Updated
PHP

Code faster using visual studio Updated 2022

by Manu July 31, 2022
written by Manu

In this guide we are going to talk about Visual studio shortcuts which can save a-lot of your development time and make you more productive. so let’s get started

here are few of the most used command short cuts.

Windows And Mac Command Keys

Check Complete list Key mapping Windows-MacOS

Open Command Prompt

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Command and P key.

Switch Between tabs

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Switch between opened tabs using

Control and 1 // Open First Tab
Control and 2 // Open Second Tab
Control and nth // Open n number Tab

Go to specific file / Search a specific file in whole project

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Go to specific file / Search a specific file

Command and p  // To open Command pallet and type file name, It should display in dropdown.

Go to specific function / Search a specific function in a file

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Go to specific function / Search a specific function in whole project

Command and p  // To open Command pallet and type # and then function name. like 

#functionNameGoesHere

// You should see function in drop down

or try

@functionNameGoesHere

Close tabs one by one / Or all at once

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Close tabs one by one / Or all at once

Command and w   // This will close open tabs one by one.(Current one closed First)

Command and k and w  // This will close all tabs at once.

Toggle Sidebar in Visual studio code

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Toggle Sidebar in Visual studio code

Command and b

Change Font of code in Visual studio code

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Command +  // Increase font size
Command -  // Decrease font size

Open 2 files Side By Side in Visual studio code

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Open one of the file you want to open and do

// This will open a new window and then you can work on 2 files. 

Command and \  

Go to start or end of line

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Command and -> // Go to extereme right of the line.
Command and <- // Go to extereme left of the line.

Move left right word by word in line.

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Shift and Option and -> // Move right word by word.
Shift and Option and <- // Move left word by word.

Duplicate code line

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Go to the code line and then press

Shift and Option and down key // Will create a duplicate in new line like copy paste

Find and replace

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Command and Option and F key

// Put keywords as you like in fields Find and replace

Select all occurrences one by one

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Select a keyword and press these keys

Command and d

Edit or add content same content in multiple lines

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Press and hold Option key and click where ever you want to add text.

At last type code or text will be added to all places where you had cursors placed.

Move code up or down

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

// Go to code line or select code block and then press

Option key and down or up arrow

Jump to specific line number

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Commnd and G key // Then type line number and hit return(Enter).

Find about function or variable

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Press and hold Command key and hover over function or variable name. // This will display you the properties there.

Open terminal in visual studio

**** These are MacOs Keys, Refer to image in this post for windows keys. ****

Command and ` 

` // Means backtick key
July 31, 2022 0 comment
0 FacebookTwitterPinterestEmail
how access token and refresh token works Updated 2022
PHP

How access token and refresh token works updated

by Manu July 17, 2022
written by Manu

In this guide we are going to see how access token and refresh token works. So in your application you want to allow user to access data if user has a access token which is not expired. fair enough now you make user getting register and you generate a access token for this user user can use this access token to access certain things in your website.

User makes a request with access token after few hours and still gets data if and only if refresh token is valid. Let’s break it down

here is the process:

  1. User registers and gets access token ( Let’s say this access token expires in 5 minutes).
  2. At the time of generating access token we generated Refresh token as well with validity of 10 minutes.
  3. User tries to get data again if access token valid user can get data.
  4. Token expires after 5 minutes
  5. Now user tries to get data but access token is expired. We check using our code logic if refresh token if expired or not.
  6. If refresh token is not expired we generate another access token for 5minutes for user.
  7. User gets access to data using new access token.
  8. This time refresh token expires.
  9. User tries to access data but access token expired as well.
  10. Our code checks for refresh token which was expired earlier.
  11. User notified that cannot access to data as both refresh and access token are expired.

At this point you can ask user to do something for getting new refresh token.

Have question want to have your code reviewed checkout “forum.ignitercode.com”. add questions there.

Download code here

July 17, 2022 0 comment
0 FacebookTwitterPinterestEmail
how to create htaccess file Updated complete guide 2022
PHP

How to create htaccess file Updated complete guide 2022

by Manu July 3, 2022
written by Manu

In this guide we are going to see htaccess redirects, authentication, removing file extension from url handling custom urls and more so let’s get started.

We will be using xampp for our testing so install xampp in your system from here.

Also if you want to check documentation for .htaccess then you can visit here for official documentations.

Ok Once you have local server up and running then we proceed.

.Htaccess file

.htaccess file is server direcive file, Where we define how we want things to go in that particular directory.

.Htaccess redirect example

So when we have xampp server running we can visit an url to see if all is set so visit “localhost”. It will redirect you to “localhost/dashboard”.

Now we can customize this redirect so lets say we have an application which has a file “index.php”. which shows “Hello” text to user.

So this application is in htdocs folder. lets call this application test so it will be in “htdocs/test” folder. ok so we can access it using url “localhost/test”.

Now we want is when we go to localhost it will redirect to localhost/test, However currently it is redirecting to localhost/dashboard.

So first go to “xampp/htdocs” folder and open index.php. This file is redirecting to “localhost/dashboard”. we can stop this redirecting by removing or commenting the code.

<?php
   if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
      $uri = 'https://';
   } else {
      $uri = 'http://';
   }
   $uri .= $_SERVER['HTTP_HOST'];
   header('Location: '.$uri.'/dashboard/');    // Here it is redirecting so comment or remove this line
   exit;                                       // also remove or comment this line too
?>
Something is wrong with the XAMPP installation :-(

So it should be like this

<?php
   if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
      $uri = 'https://';
   } else {
      $uri = 'http://';
   }
?>
Something is wrong with the XAMPP installation :-(

Now you will see “Something is wrong with the XAMPP installation :-(” text on the page. Let’s add our redirect now which will redirect to “localhost/sky”.

So inside “xampp/htdocs” folder create a file “.htaccess” and add this code.

htaccess Redirect to Subfolder

RewriteEngine On
RewriteRule ^$ /sky [L]

There you see it works.

Authentication in htaccess file

For Authentication you can add this code

RewriteEngine On
AuthName "Restricted Content"
AuthType Basic
AuthUserFile .htpasswd
Require valid-user

For AuthUserFile you will need to get Root path, you can use

echo $_SERVER['DOCUMENT_ROOT']; // To check the Document root path

Here basically we are sing that ask for user name and password. if authenticated then proceed. otherwise not.

Ok we in line

AuthUserFile .htpasswd

We are sing user name and password should match what we have in file “.htpasswd”. which is in the same directory

// .htpasswd file has below gien username and password

john:$apr1$jpnymgh2$wnxzM01O9Qk5yPubimHPo.

You can have any username or password here just to show you what process looks like we added user as john.

Here we need to authenticate. Before accessing the page. Password in encrypted you can get your password encrypted from google just search for “htpasswd generator”.

If you face problem anywhere check apache error logs. It is in “htdocs/logs” directory

Using Cache in htaccess

For caching images you can use this code

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
	Header set Cache-Control "max-age=86400, public"
</Filesmatch>

So i added one image in page and refreshed it next time when i refreshed, then image loaded from cache. Have a look

It also shows when cache will expire which is “1day”.

Removing file extension using .htaccess

For this we need to add this code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

See Here we say “$1.php” where we are saying accept without .php so we can now load page without .php extension.

See all works

Handle custom url using htaccess

Ok now we need to do this, So for example if we have api in url then we need to load some certain file. so here how we can achieve this

add this line in .htaccess

RewriteEngine On
RewriteRule ^api index.php

So we are saying if there has “api” word in url then show index.php

How to Set a Custom 404 Page With .htaccess

Lets configure error pages for 404 page we create a folder “errors” and then we create files inside it for example. “404_error.php”.

RewriteEngine On
ErrorDocument 404 /sky/errors/404_error.php // Remember path should be from document root

Now add any text in 404_error.php that will display on web page.

We can add more pages for other error codes just the same way.

Redirect to index.php instead going to error pages .htaccess

RewriteEngine On


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule . /sky/index.php // our app folder is called sky so sky/index.php we redirected to.
July 3, 2022 0 comment
0 FacebookTwitterPinterestEmail
React blog application with php backend complete guide with api development 2022
PHPReactJS

React blog application with php backend complete guide with api development 2022

by Manu July 3, 2022
written by Manu


In this guide you will see how to develop react blog application along with api development using php, We are going to have front code separate from backend code. and frontend will fetch data from api endpoints.

Important Commands to install required packages.

npm install styled-components
npm install react-router-dom@6
npm i chakra-paginator
npm i @chakra-ui/icons


npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^6

July 3, 2022 0 comment
0 FacebookTwitterPinterestEmail
Web socket crash course 2022 updated step by step
NodeJSPHPSocket.io

Web socket crash course 2022 updated step by step

by Manu July 3, 2022
written by Manu

In this guide we are going to see web socket in action. So we use web sockets for chat systems and for notification systems where you want to show content without refreshing page.

Or you might use web sockets with web hooks.

Technologies used

Node, Composer, Javascript, PHP. So without waiting any further let’s get started.

we need to create 2 files. First js file and second php file here .

Create a project folder and run command

// To initiate npm

npm init -y 

This will create a default settings in package.json file. then you need to install few packages so here are the commands

// Installing socket.io

npm install --save socket.io

// Installing Express

npm install --save express


// For php we need to install elephant.io

composer require wisembly/elephant.io

Before running these commands make sure you have node and composer installed in your system. After installing these packages create

First server.js file

let socket = require('socket.io')(3001),
    express = require('express'),
    https = require('https'),
    http = require('http');



let app = express();
let http_server = http.createServer(app);


let io = socket.listen(http_server);
io.sockets.on('connection', function(socket){
    socket.on("new_event", function(data){
        console.log(data);
    });
});

Here basically we are calling packages and then creating an app using express. then using app we created a server.

Afterwards we are listening to that server on port 3001.

what ever data we get from php file we are going to console log it.

Here is php file code

<?php
error_reporting(E_ALL);        // displaying error
ini_set('display_errors', 1);  // displaying error


include("vendor/autoload.php");    // including composer packages files


use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version2X as Version2X;;



$version = new Version2X("http://localhost:3001");     // Binding to port 3001
$client = new Client($version);


$client->initialize();
$client->emit("new_event", [
    "test" => "test",
    "test1" => "test1"
]);
$client->close();

Here we return data as “new_event”.

Ok testing time

open terminal and go to project folder where we have js and php file.

so if file name is server.js then run this file using below given command.

node server

then open php file in browser and refresh page you should see some content printed on terminal . Here have a look

See same data we are returning in php file.

Important Commands

// Kill-stop all running node servers.

killall node

// Run node server.

node filename for example 
node server.js or node server  // as our file is server.js

// Run nodejs in background

node filename > /dev/null 2>&1 &   

node server > /dev/null 2>&1 &   

Hope this helps.

July 3, 2022 0 comment
0 FacebookTwitterPinterestEmail

Recent Posts

  • ecommerce cart react source code 2022 [ For Beginners ]
  • How to use stored procedure in sql updated 2022
  • Must know mysql functions updated 2022
  • Why and how to use sql views 2022
  • how to import csv to mysql using php

Recent Comments

No comments to show.
  • Facebook
  • Twitter
  • Youtube
  • Email

@2022 - All Right Reserved


Back To Top
Igniter Code
  • Home
  • ZarxBiz
  • Forum