Giter VIP home page Giter VIP logo

php_curl_command_linux's Introduction

Php_curl_command_linux for creating thread

Here we can run a PHP file (script) in background, This process is hidden to the end user. IT improves your Website efficiency.

EXECUTE PHP SCRIPT IN BACKGROUND PROCESSING

The scenario, when we need to run some script without waiting the fronted user till the process is not completed, For that we need to execute some script in background to hiding the execution time to user.

The Concept, In LINUX there is a shell script with is Used to run the process in background. You can put a task (such as command or script) in a background by appending a & at the end of the command line. The & operator puts command in the background and free up your terminal. The command which runs in background is called a job. You can type other command while background command is running.

Syntax : {command} &

Example: ls -l & exec php index.php > /dev/null 2>&1 & echo $!

How to check the background process in Linux?

ps -l (list all process)
ps -ef (all full details of process)

What is the command to execute a php file in background?

Syntax: nohup exec </path/to/php/> <path/to/your/phpfile> arg1 arg2 > /dev/null &

Example: nohup exec php process.php hello world > /dev/null &

What is nohup?

Most of the time you log-in into remote server via ssh. If you start a shell script or command and you exit (abort remote connection), the process / command will get killed. Sometime job or command takes a long time. If you are not sure when the job will finish, then it is better to leave job running in background. But, if you log out of the system, the job will be stopped and terminated by your shell. What do you do to keep job running in the background when process gets SIGHUP?

The answer is simple, use nohup command line-utility which allows to run command/process or shell script that can continue running in the background after you log out from a shell:

nohup command syntax: nohup command-name &

What is exec?

This command is used to execute a process in Linux. It can process one or more process at a time.

How to use this PHP library on your code?

Step 1: create two file name index.php and process.php

step 2: include the PHPBackgroundProcesser.php file in the index.php

step 3: create a instance of the class BackgroundProcess

We can use this:

Type 1:
$proc=new BackgroundProcess('exec php <BASE_PATH>/process.php hello world');

Type 2:
$proc=new BackgroundProcess();
$proc->setCmd('exec php <BASE_PATH>/process.php hello world');
$proc->start();

Type 3: 
    $proc=new BackgroundProcess();
$proc->setCmd('exec php <BASE_PATH>/process.php hello world')->start();

Alternate way to do the PHP URL execute in background with out the direct (.php) file.
    $process=new BackgroundProcess("curl -s -o <Base Path>/log/log_storewav.log <PHP URL to execute> -d param_key=<Param_value>");

How to get all process which is running?

    $proc=new BackgroundProcess();
print_r($proc->showAllPocess());

How to kill a process ?

$proc=new BackgroundProcess();
$proc->setProcessId(101)->stop(); //set the process id.


#This Refrence from https://tricks-tips-forcomputer.blogspot.com

php_curl_command_linux's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.