One attempt, with a progress bar.

#!/usr/bin/php
<?php
if (@$argv[1] != null){
  echo "Retrieving http header..."; 
  $header = get_headers("$argv[1]");
  $pp = "0";
  echo json_encode($header, JSON_PRETTY_PRINT);
  $key = key(preg_grep('/\bLength\b/i', $header));
  $type = key(preg_grep('/\bType\b/i', $header));
  $http = substr($header[0], 9, 3);
  $tbytes = @explode(" ",$header[type = @explode("/",explode(" ",$header[$type])[1])[1];
  echo " Target size: ".floor((($tbytes / 1000)/1000))." Mo || ".floor(($tbytes/1000))." Kb";
  $t = explode("/",$argv[1]);
  $remote = fopen($argv[1], 'r');
  t[count(type";
  $local = fopen(read_bytes = 0;  
  echo PHP_EOL;
  while(!feof($remote)) {
    $buffer = fread($remote, intval($tbytes));
    fwrite($local, $buffer);
    $read_bytes += 2048;
    $progress = min(100, 100 * $read_bytes / $tbytes);
    $progress = substr($progress,0 , 6) *4;
    $shell = 10; /* Progress bar width */ 
    shell * $progress / 100;
    echo " \033[35;2m\e[0m Downloading: [".round($progress,3)."%] ".floor((($read_bytes/1000)*4))."Kb ";
    if (shell){$pp=0;};
    if ($rt === $shell){$rt=0;};
    echo str_repeat("█",$rt).str_repeat("=",($pp++)).">@\r";
    usleep(1000);
  }
  echo " \033[35;2m\e[0mDone [100%]  ".floor((($tbytes / 1000)/1000))." Mo || ".floor(($tbytes/1000))." Kb   \r";
  echo PHP_EOL;
  fclose($remote);
  fclose($local);
}

The file is build directly into the current folder, not in the temp directory. This mean the file can be read while downloading. If the file type is made to handle that, like most media format do.

To use, pass an url as first argument in the command line.

./pget  https://site.download.mp4

You know you want to tweek it ;)

Answer from NVRM on Stack Overflow
🌐
GitHub
github.com › crazywhalecc › static-php-cli
GitHub - crazywhalecc/static-php-cli: Build standalone portable PHP binaries on Linux, macOS, Windows, with PHP project together, with popular extensions included. · GitHub
The current README contains basic usage. For all the features of static-php-cli, see https://static-php.dev . If you don't want to build or want to test first, you can download example pre-compiled artifact from Actions, or from self-hosted server.
Starred by 1.8K users
Forked by 364 users
Languages   PHP 95.8% | Shell 1.9% | JavaScript 1.0% | PowerShell 0.5% | C 0.5% | M4 0.3%
🌐
Pkgs.org
pkgs.org › download › php-cli
Php-cli Download for Linux (apk, deb, rpm)
Download php-cli packages for AlmaLinux, Alpine, Amazon Linux, CentOS, Debian, Fedora, Mageia, OpenMandriva, openSUSE, PCLinuxOS, Rocky Linux, Ubuntu
Top answer
1 of 3
6

One attempt, with a progress bar.

#!/usr/bin/php
<?php
if (@$argv[1] != null){
  echo "Retrieving http header..."; 
  $header = get_headers("$argv[1]");
  $pp = "0";
  echo json_encode($header, JSON_PRETTY_PRINT);
  $key = key(preg_grep('/\bLength\b/i', $header));
  $type = key(preg_grep('/\bType\b/i', $header));
  $http = substr($header[0], 9, 3);
  $tbytes = @explode(" ",$header[type = @explode("/",explode(" ",$header[$type])[1])[1];
  echo " Target size: ".floor((($tbytes / 1000)/1000))." Mo || ".floor(($tbytes/1000))." Kb";
  $t = explode("/",$argv[1]);
  $remote = fopen($argv[1], 'r');
  t[count(type";
  $local = fopen(read_bytes = 0;  
  echo PHP_EOL;
  while(!feof($remote)) {
    $buffer = fread($remote, intval($tbytes));
    fwrite($local, $buffer);
    $read_bytes += 2048;
    $progress = min(100, 100 * $read_bytes / $tbytes);
    $progress = substr($progress,0 , 6) *4;
    $shell = 10; /* Progress bar width */ 
    shell * $progress / 100;
    echo " \033[35;2m\e[0m Downloading: [".round($progress,3)."%] ".floor((($read_bytes/1000)*4))."Kb ";
    if (shell){$pp=0;};
    if ($rt === $shell){$rt=0;};
    echo str_repeat("█",$rt).str_repeat("=",($pp++)).">@\r";
    usleep(1000);
  }
  echo " \033[35;2m\e[0mDone [100%]  ".floor((($tbytes / 1000)/1000))." Mo || ".floor(($tbytes/1000))." Kb   \r";
  echo PHP_EOL;
  fclose($remote);
  fclose($local);
}

The file is build directly into the current folder, not in the temp directory. This mean the file can be read while downloading. If the file type is made to handle that, like most media format do.

To use, pass an url as first argument in the command line.

./pget  https://site.download.mp4

You know you want to tweek it ;)

2 of 3
0

In my opinion, the easiest way is:

$fileContent = file_get_contents('/home/lokesh/lalu.txt');

If I correctly understood.

🌐
PHP
php.net › downloads.php
PHP: Downloads
Development package (SDK to develop PHP extensions) 1.64MB sha256: 8680c6b7525f0e27446bcaa5be5d28ddcc25e668e0a7ca8fef68b2739e772810
🌐
GitHub
github.com › adhocore › php-cli
GitHub - adhocore/php-cli: PHP Console Application made easy- build great console apps with ease. Comes with Zero Dependency and Autocompletion support. Think of it as extremely flexible and customizable PHP cli application framework. · GitHub
PHP Console Application made easy- build great console apps with ease. Comes with Zero Dependency and Autocompletion support. Think of it as extremely flexible and customizable PHP cli application ...
Starred by 350 users
Forked by 39 users
Languages   PHP 99.3% | Shell 0.7%
🌐
GitHub
github.com › splitbrain › php-cli
GitHub - splitbrain/php-cli: PHP library to build command line tools · GitHub
PHP library to build command line tools. Contribute to splitbrain/php-cli development by creating an account on GitHub.
Starred by 176 users
Forked by 40 users
Languages   PHP
🌐
Sdsc
hpcshare.sdsc.edu › help › how-to-install-php
How to install PHP? (For Command Line use only) | SDSC HPC Share
# Fetch php7.2.28 source curl -o php-7.2.28.tar.gz -L http://php.net/get/php-7.2.28.tar.gz/from/this/mirror # untar php source tar xzf php-7.2.28.tar.gz cd php-7.2.28 # Configure php for minimal build that we need for the FolderShare client # Optionally add --prefix=/path/to/install ./configure --disable-all --disable-cgi --enable-cli --enable-filter --enable-json --enable-mbstring --with-curl --with-readline # build make # make install #if you added prefix # Add environment path to find php export PATH=`pwd`/sapi/cli:$PATH" #change this path if you added prefix # Check if php is now in environment path php -v # Consider adding the php path in your shell profile (e.g.
🌐
WP-CLI
wp-cli.org
WP-CLI | WP-CLI
Once you’ve verified requirements, download the wp-cli.phar file using wget or curl: curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar · Next, check the Phar file to verify that it’s working: php wp-cli.phar --info · To use WP-CLI from the command line by typing wp, make the file executable and move it to somewhere in your PATH.
Find elsewhere
🌐
RPMfind
rpmfind.net › linux › rpm2html › search.php
RPM resource php-cli
The php-cli package contains the command-line interface executing PHP scripts, /usr/bin/php, and the CGI interface.
🌐
IONOS
ionos.com › help › hosting › using-php-for-web-projects › executing-php-files-via-the-command-line-php-cli
Executing PHP files via the command line (PHP CLI) - IONOS Help
In the following you will learn how to use PHP CLI to execute PHP files in your webspace. ... An SFTP account with SSH support. Further information can be found in the article Creating an SFTP/SSH account. The connection data for your SFTP account. Further information can be found in the article Connection data for Secure FTP. A device with an installed SSH program (SSH client). For computers with a Windows operating system, we recommend the PuTTY program. Download PuTTY.
🌐
PHP
windows.php.net › download
PHP For Windows: Binaries and sources Releases
If you like to build your own PHP binaries, instructions can be found on the Wiki. PECL extensions for Windows is being worked on. Windows DLL can be downloaded right from the PECL website.
🌐
GitHub
github.com › wp-cli › php-cli-tools
GitHub - wp-cli/php-cli-tools: A collection of tools to help with PHP command line utilities · GitHub
A collection of tools to help with PHP command line utilities - wp-cli/php-cli-tools
Starred by 682 users
Forked by 115 users
Languages   PHP
🌐
Minicli
docs.minicli.dev
Minicli
Since version 4.0, Minicli requires PHP 8.1. ... Apart from that, you'll need Composer to install and use Minicli. Minicli is committed to creating a safer software supply chain ecosystem, that's why we don't bring any chained dependencies with the base minicli/minicli package. Starting from version 3.2.0, we also include SBOM files with every release of Minicli. You can download here our latest SBOM in SPDX format.
🌐
Debian
packages.debian.org › bullseye › php-cli
Debian -- Details of package php-cli in bullseye
This package provides the /usr/bin/php command interpreter, useful for testing PHP scripts from a shell or performing general shell scripting tasks.