Questions tagged [shell-exec]

The shell_exec() PHP function provides the ability to run shell commands during the execution of a script.

The shell_exec() function provides the ability to run shell commands during the execution of a script. Other similar functions include, exec(), system(), passthru(), and the use of backticks around the command (``). It is important to note that commands executed this way will be run under the same permissions as the user that started the original process (i.e. calling this from a web page processed by Apache will run this under the same user Apache uses, typically httpd).

This functionality becomes handy when the developer wishes to execute a command which no API, library or extension for PHP exists. Example, a script you are developing needs to display the output of the UNIX vmstat command. PHP does not have visibility into such information, so the use of shell_exec('vmstat'); becomes warranted.

This function can be a security risk and, as such, this function is commonly disabled in shared hosting environments.

1065 questions
3
votes
1 answer

PHP shell_exec returns empty string after a while

I made a Symfony console command which uses pngquant to process and compress a long list of images. The images are read from a CSV file. The batch is working fine until the end in local environment but in the stage environment it works for about 5…
StockBreak
  • 2,857
  • 1
  • 35
  • 61
3
votes
4 answers

php shell_exec() out put to get a text file

I'm trying to run rate -c 192.168.122.0/24 command on my Centos computer and write down the output of that command to the text file using shell_exec('rate -c 192.168.122.0/24') command; still no luck!!
Roshan Wijesena
  • 3,106
  • 8
  • 38
  • 57
3
votes
1 answer

shell_exec return NULL

when i run the code shell_exec('ping -c 4 127.0.0.1') it returns NULL, but when I run the same command (ping -c 4 127.0.0.1) in ssh, it returns perfectly... and yes, the script can run shell_exec, I tried shell_exec('ls') and it returns correctly,…
Quicky
  • 163
  • 2
  • 7
3
votes
1 answer

PHP Output correct in terminal but not in browser

I just started working with shell_exec in php and stuck at this point. Below is my php script which runs in terminal correctly but not in browser. And output in terminal is $ php…
3
votes
2 answers

PHP exec/shell_exec/system not working through browser

I am running an SCO Unix box with apache version 1.3.33 and PHP version 4.4. I can properly execute the exec command through the cli, but run into trouble with trying to execute the script via a browser. My settings are: safe mode off full…
user320487
3
votes
1 answer

Why is exec() silently discarding bytes?

After a lot of struggling, I found out some behavior I can't explain / solve, so asking here for help. On our server (Ubuntu 16.04.5 LTS with PHP 7.0.30), we're using some tools outside of the 'httpdocs', which are called using exec() to get their…
Bazardshoxer
  • 545
  • 1
  • 5
  • 22
3
votes
1 answer

Why is the result equal to 0 and sometimes 1 - shell_exec('pgrep -f

The script: $S = 'pgrep -f test.php | wc -l'; $U = trim(shell_exec($S)); echo $U; Why is the result of this script equal to 0 and sometimes 1 ? The file test.php is not running.
mysql
  • 33
  • 2
3
votes
1 answer

laravel controller shell_exec('composer update');

I would like to execute the following command : composer update in my controller in laravel, however this one does not work. On the other hand the command composer info works perfectly. When I execute composer update in a command prompt all my…
HIBO
  • 31
  • 4
3
votes
0 answers

Restart Apache from php error " Found 1 leftover httpd processes "

I want to restart apache from php. I use this code The output is this error Stopping httpd: [FAILED] Found 1 leftover httpd processes. Killing. Starting httpd: Does…
Alexis
  • 56
  • 4
3
votes
0 answers

PHP - How to start google chrome with PHP script

Here is my code: $output"; ?> Here is what i have in test.sh: #!/bin/bash export DISPLAY=:0 google-chrome echo "Starting Chrome" When i execute ./test.sh google-chrome is…
Venelin
  • 2,905
  • 7
  • 53
  • 117
3
votes
1 answer

Bash script live output executed from PHP

I'm trying to execute a bash script from php and getting its output in real time. I am applying the answers found here: However they are not working for me. When I invoke the .sh script on this way, it works fine:
Zumo de Vidrio
  • 2,021
  • 2
  • 15
  • 33
3
votes
1 answer

Powershell output to PHP variable using shell_exec

I have a powershell script which outputs a video file duration. Running this script gives me the expected result. $Folder = 'C:\my\path\to\folder' $File = 'sample1_1280_720.mp4' $LengthColumn = 27 $objShell = New-Object -ComObject Shell.Application…
Thomas
  • 315
  • 1
  • 5
  • 15
3
votes
1 answer

Execute a Java Application from Php

Hi friends I have to execute a java application from php script , for that I have moved the jre folder files to xammp folder and set the path to the folder . I have tested using a sample java program like PHP Script:
500rs Dreams
  • 33
  • 1
  • 3
3
votes
1 answer

PHP Shell_exec - Powershell not running

I am trying to run this: shell_exec("powershell -File C:\inetpub\wwwroot\altirisinstall\startinstall.ps1 $computername > /dev/null &"); It works fine as long as I remove: /dev/null & However, that makes the website pause and wait for the script…
Jack
  • 31
  • 5
3
votes
2 answers

Apache user privileges in Centos

Hi I'm using the shell_exec command from a PHP script: $output = shell_exec('ls -l'); print_r($output); Terminal: php test.php Which results in the directory listing as expected. Switch to my browser I get no output. I need to grant privileges to…
StuR
  • 12,042
  • 9
  • 45
  • 66