PHP - Shell_exec Hangs Page...
Hello all,
I am using a shell_exec command like the one below: $output = shell_exec('c:\powershell\powershell.exe get-service'); echo($output); However, when launching the page, the browser will hang with the hour-glass. If i end the powershell.exe process on the web server via task manager, the browser then returns the expected output. Any idea why this is? Other commands, like ipconfig return the correct output and the browser displays "Done" in the bottom left. Any help appreciated. Andrew Similar TutorialsHey i have a script using COMET server push effect, but it causes my browser to hang and i cannot understand why. Heres the script that deals with PHP: <?php session_name('Current_User'); session_set_cookie_params(0, '/', '.mydomain.com'); // i use a subdomain so this is needed session_start(); include("connect.php"); function getNewMessagesSince($timestamp) { $Get = mysql_query("SELECT Count(push) AS Total FROM messages WHERE LastUpdate='$timestamp'") or die(mysql_error()); $row = mysql_fetch_assoc($Get); if($row['Total'] != 1) { $Get = mysql_query("UPDATE push SET LastUpdate='".time()."'") or die(mysql_error()); $Get = mysql_query("SELECT Message FROM messages WHERE Deleted='0' ORDER BY postedon DESC LIMIT 1") or die(mysql_error()); $row = mysql_fetch_assoc($Get); return array( 'lastupdate' => time(), 'html' => $row['Message'].' <br/>' ); } return false; } while(! ($row = getNewMessagesSince($_POST['lastupdate']))) { //every half a second usleep(50000); } echo json_encode($row); ?> Any ideas on what i got wrong ? Hi Guys I cant seem to get unzip to work via php shell_exec this is what I have: Code: [Select] $rworld = $_GET['restore']; $connect->call('remotetoolkit.stopServer',Array()); sleep(12); $nrworld = substr($rworld, 0,-15); $sftp = new Net_SFTP($host); $sftp->login($root_user, $root_pass); $sftp->delete('/root/minecraft/'.$nrworld.'/', true); echo shell_exec("unzip -jo /root/minecraft/saves/$rworld -d /root/minecraft/$nrworld"); sleep(5); $connect->call('remotetoolkit.startServer',Array()); Nothing is returned, it doesn't echo and the command is not executed. If I execute via terminal and change the $variables to the actual names it works fine, and I can ls with shell_exec successfully? Any ideas? Good Friday to everyone! I am writing some PHP code to find certain files and the search the files for a certain string. For example, this is what I have. This works in a LINUX shell environment, yet I need to have it work in PHP since the GUI is web based. Can anyone help? Thanks! Mike Code: [Select] <?php $output = shell_exec('find /sync/www/html/ohx/products/MEMNPWOHX* -type f -exec grep "HEAT ADVISORY IN EFFECT" /dev/null {} \;'); echo "<pre>$output</pre>"; ?> I'm trying to call a command using shell_exec by doing the following- Quote shell_exec("C:\\myprogram.exe -t")or die('error'); but that doesn't work, as it returns 'error'. The command "C:\\myprogram.exe -t" works perfect when i call it myself using the cmd.exe but not when i try using it in php with shell_exec. Safe mode is off and i'm using apache as my php webserver. Does anyone know what the problem is here and if not then is there any other ways of executing myprogram.exe in php? This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=344940.0 Hi im Art, Im trying to make use of Shell_exec() function to execute gammu(smsgateway for linux<CLI>) to text a message using my php page. This is my actual code: <html> <form method="POST"> Message: <textarea name=Message></textarea> Number: <input type=Text name=Number> <Input type=Submit name=Send value=Send> </form> </html> <?php extract($_POST); if (isset($Send)){ $output = shell_exec("pwd"); echo $output."<br>"; $cmd="gammu --identify"; echo $cmd."<br>"; $output = shell_exec($cmd); echo $output; $cmd="echo '".$Message."'|gammu sendsms TEXT ".$Number; echo $cmd."<br>"; $output = shell_exec($cmd); echo $output; } ?> But this is the error: /opt/lampp/htdocs gammu --identify Error opening device, you don't have permissions. echo 'Hi There'|gammu sendsms TEXT +639270000000 Error opening device, you don't have permissions. PS: It works well if just issue the command echo 'Hi There'|gammu sendsms TEXT +639270000000 on my terminal but i dont know why it doesnt work for php, and another thing, i wasnt using any sudo commands on shell i just type the command directly, hope someone can help me out thanks When i try to do a shell_exec from my script the script does not work. But when i put the same thing in a .bat file and execute that from PHP it wroks. Can anyone help me shell_exec('xcopy C:\xampp\htdocs\test\backup\test.zip "\\fileserver\KT_backup\aback\" /i') Hi guys, I'm running the following code: Code: [Select] $result = shell_exec("su user; scp /path/to/file/text.txt user@domain:/path/to/file/text.txt"); Now, the file get's transferred correctly. However, I need to put in place a check to check if the transfer was successful. $result seems to return the same whether the transfer was successful or not. I want to send an email to state whether the file transfer was successful so what do I need to do to check this? Thanks! I am using shell_exec, and it runs a ping on a server, is there any way to flush the buffer of the shell_exec as the data is getting written to the buffer? Because I sometimes ping a site 10 times and nothing get written until the function finishes, so is there anyway to write out the output as soon as it is available? btw, this isn't only for doing a ping it is for other things as well. In the browser when I open the file I need to see the output of the ifconfig linux command on the server. This is the index.php <? $iplist = shell_exec("ifconfig"); print "<pre>$iplist</pre>"; ?> but when I open the index.php in a browser I can see only the first couple of lines, nothing more. Can someone help me what to do? The strange thing is when I run the index.php from the command line with "php index.html" it shows the correct result. Any help..? Thanks, Debian 5 PHP 5.2.6-1 This script works: <? $output = shell_exec('ls -lart'); echo "<pre>$output</pre>"; ?> This script doesn't work: <? $vars=unserialize(file_get_contents("file.txt")); $output = shell_exec('ls -lart'); echo "<pre>$output</pre>"; ?> I get error: Quote Warning: shell_exec(): Unable to execute 'ls -lart' or Warning: system(): Unable to fork [ls -lart] If file.txt has size 500k, the script works without errors. But my file file.txt has size 30M. Help. NB: oh yeah, the specs: PHP 5.5.9-1ubuntu4.4 Server version: Apache/2.4.7 Ubuntu 14.04-4
OK, this is driving me completely nuts.
Yes, the first problem is, I'm modifying someone else' code, so I'm trying to cludge this, but I don't have the time resources to write the entire application, at least not at this prototype stage.
That said, start_exec() works wonderfully in a standalone, test script, so there's nothing wrong with the server or php mods / version.
The scenario, on clicking an href or button, I want a script to run (it loads files from a remote sftp and also wgets from another server). One would think this isn't much of a problem, so here's where it becomes crazy making.
The code I'm working with is generating the html with print() in the form of print "<html>";
I've tried the usual examples for doing this function, but none of them are using embedded php in embedded html.
So this:
print"<tr><td class=leftsub><div width=100% class=info id=tasks> <a href='windows.php?pull=true'><img src=images/explore.gif width=16 height=16> <u>Pull files from server</u></a><br>does not invoke this: if ($_GET['pull']) { # This code will run if ?pull=true is set. shell_exec('pull.sh'); }Which is all in the local function. And this doesn't work either: print "<img src=images/extract.gif onClick='shell_exec('./pull.sh')' class=button title='Pull files'>";Nor does this: print ("<form method='post'><p><button name='button'>Run Perl</button></p></form>");seem to call this: if (isset($_POST['button'])) shell_exec('./pull.sh');There are other ways I could perform the same, even just a cron that pulls and pushes on some regular interval, of couse which is checking to see if the files are open before pulling or pushing, but I'd rather it be on demand. Am I just going to drive myself nuts without re-writing the entire code? Should I rather just have the requests call a different php script which then inline shell_exec()'s the shell script? Any insight and feedback is very much appreciated. Cheers, Kevin Edited by krattai, 21 September 2014 - 01:43 PM. if(isset($_POST['clearflags'])){ $output = shell_exec('php clearflags.php'); } The above works fine on my local development server running Debian 10, PHP 7.4 and Apache 2.4.25. clearflags.php is a script that clears various fields in a MySQL database so it's easy to determine if it properly ran or not. On my hosted server however (Bluehost), clearflags.php is never executed. My hosting service swears that SAFE MODE is not on in PHP (which is also Version 7.4). If I call from the command line (php clearflags.php), it runs fine. $output on the hosted server is "Content-type: text/html; charset=UTF-8 " but nothing on my local server where the script is called and runs OK. No entry appears in the error log about this I've also tried using exec() with the same failed result Running phpinfo() on the hosted server shows that disabled_functions are "no value" Thoughts? Edited October 11, 2020 by KenHorseQuesion: Show each movie in the database on its own page, and give the user links in a "page 1, Page 2, Page 3" - type navigation system. Hint: Use LIMIT to control which movie is on which page. I have provided 3 files: 1st: configure DB, 2nd: insert data, 3rd: my code for the question. I would appreciate the help. I am a noob by the way. First set up everything for DB: <?php //connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //create the main database if it doesn't already exist $query = 'CREATE DATABASE IF NOT EXISTS moviesite'; mysql_query($query, $db) or die(mysql_error($db)); //make sure our recently created database is the active one mysql_select_db('moviesite', $db) or die(mysql_error($db)); //create the movie table $query = 'CREATE TABLE movie ( movie_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, movie_name VARCHAR(255) NOT NULL, movie_type TINYINT NOT NULL DEFAULT 0, movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0, movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0, movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (movie_id), KEY movie_type (movie_type, movie_year) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); //create the movietype table $query = 'CREATE TABLE movietype ( movietype_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, movietype_label VARCHAR(100) NOT NULL, PRIMARY KEY (movietype_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); //create the people table $query = 'CREATE TABLE people ( people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, people_fullname VARCHAR(255) NOT NULL, people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (people_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Movie database successfully created!'; ?> ******************************************************************** *********************************************************************** second file to load info into DB: <?php // connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //make sure you're using the correct database mysql_select_db('moviesite', $db) or die(mysql_error($db)); // insert data into the movie table $query = 'INSERT INTO movie (movie_id, movie_name, movie_type, movie_year, movie_leadactor, movie_director) VALUES (1, "Bruce Almighty", 5, 2003, 1, 2), (2, "Office Space", 5, 1999, 5, 6), (3, "Grand Canyon", 2, 1991, 4, 3)'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the movietype table $query = 'INSERT INTO movietype (movietype_id, movietype_label) VALUES (1,"Sci Fi"), (2, "Drama"), (3, "Adventure"), (4, "War"), (5, "Comedy"), (6, "Horror"), (7, "Action"), (8, "Kids")'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the people table $query = 'INSERT INTO people (people_id, people_fullname, people_isactor, people_isdirector) VALUES (1, "Jim Carrey", 1, 0), (2, "Tom Shadyac", 0, 1), (3, "Lawrence Kasdan", 0, 1), (4, "Kevin Kline", 1, 0), (5, "Ron Livingston", 1, 0), (6, "Mike Judge", 0, 1)'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Data inserted successfully!'; ?> ************************************************************** **************************************************************** MY CODE FOR THE QUESTION: <?php $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('moviesite', $db) or die(mysql_error($db)); //get our starting point for the query from the URL if (isset($_GET['offset'])) { $offset = $_GET['offset']; } else { $offset = 0; } //get the movie $query = 'SELECT movie_name, movie_year FROM movie ORDER BY movie_name LIMIT ' . $offset . ' , 1'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); ?> <html> <head> <title><?php echo $row['movie_name']; ?></title> </head> <body> <table border = "1"> <tr> <th>Movie Name</th> <th>Year</th> </tr><tr> <td><?php echo $row['movie_name']; ?></td> <td><?php echo $row['movie_year']; ?></td> </tr> </table> <p> <a href="page.php?offset=0">Page 1</a>, <a href="page.php?offset=1">Page 2</a>, <a href="page.php?offset=2">Page 3</a> </p> </body> </html> Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=323045.0 I have a page with results from a query that displays that has a link (works fine - passes variables etc) that deletes that line item from a database. It goes to the delete.php and actually executes and removes the item from the database and then has the line header("Location: page.php"); which returns BACK to the page displaying the results. However, it shows the old results until I hit Refresh in the browser. Its like the header is redirecting to a cached version of the page.
NOTE: This script used to work fine untouched when we where on a shared hosting account. We JUST updates to VPS hosting by the same host. Now this problem has risen and I can't figure out what is wrong. From what I can guess is there is something in php.ini that is either not set, set or set wrong. Any help would be greatly appreciated.
Thanks.
I am using Magento (Ver 1.9.x) If i try with my localhost success url like, http://192.168.1.65/magento/index.php/checkout/onepage/success/ and return success message with order id. if i try with live, success url like, https://abc.in/payubiz/redirect/success/ success page like blank page. How to solve the issue? Code : https://github.com/ZusZus/Payubiz Edited February 4, 2020 by aveevaHi, Is it possible to build a PHP Template page that selects and publishes a row of data from a MySQL Database when a linked is clicked? I would design: Template.php Text links (perhaps on homepage of navigation bar): ProductA, ProductB and ProductC If you click link ProductA Template.php would display data for ProductA and likewise for ProductB and ProductC. I would also like search engines for find ProductA, ProductB and ProductC PHP pages. (Not just my single Template.php) Any ideas as to how this could be done without designing individual PHP pages for each product? Kind regards, Matthew. Hi, I am a php newbie, who has a page that relies on some php scripts, and to which I am trying to add a login page written in php. I took the example from he http://www.howtodothings.com/computers-internet/how-to-make-a-login-system-for-your-website Basically it consists of adding: <? require("log.php"); ?> to the top of any page I want to protect, a log.php file which performs the actions of the form, linking to a mySQL database, and a login.php file which contains the form. I have the login working fine, but it breaks one of the PHP scripts on the page that is protected. It is an upload script, called Weaverbox, based on FancyUpload. The uploads which are handled by a file called upload.php, aren't happening. The progress shows that they are being uploaded, but nothing is uploaded, and there is no success message. As soon as I remove the code from the top of the page requiring log.php all works fine again. I think I may have to add some rules/extensions to resolve this conflict, but I don't know how to go about this. Would someone be able to help me get it sorted? Thanks Nick |