Jump to content

Script timing out


ben m

Recommended Posts

Hi All,

 

I was hoping someone might be able to point out an easy error with this code or maybe some insight into why I am having problems.

 

First off here is the code:

 

if (empty($_POST['ud_mysql'])) {
	$ud_hasmysql			= "0";
} else {
	$ud_hasmysql			= "1";
}

$mysql_query="SELECT mysql FROM $db.$db_table WHERE id='$ud_id'";
$mysql_result=mysql_query($mysql_query);
$has_mysql=mysql_result($mysql_result,$i,"mysql");

if ($has_mysql != $ud_hasmysql) { // if the MySQL checkbox value from details page does not match what the database holds for the MySQL value then a change has been made

	if ($ud_hasmysql == "1") { // If the check box is selected then install MySQL and phpMyAdmin

		//// Enable MySQL
//			$out		= explode("\n", shell_exec("sudo /usr/share/webmin/virtual-server/enable-feature.pl --domain $ud_domain --mysql"));
//			foreach ($out as $i) {
//				echo "$i</br>";
//			}

		//// Install phpMyAdmin
		$out		= explode("\n", shell_exec("sudo /usr/share/webmin/virtual-server/install-script.pl --domain $ud_domain --version latest --type phpmyadmin --path /phpmyadmin/"));
		foreach ($out as $i) {
			echo "$i</br>";
		}; 
//			echo "sudo /usr/share/webmin/virtual-server/install-script.pl --domain $ud_domain --version latest --type phpmyadmin --path /phpmyadmin/"; //testing

	} elseif ($ud_hasmysql == "0") { // If the check box is not selected then uninstall MySQL and phpMyAdmin
		//// Uninstall phpMyAdmin
//			$out		= explode("\n", shell_exec("sudo /usr/share/webmin/virtual-server/delete-script.pl --domain $ud_domain --type phpmyadmin"));
//			foreach ($out as $i) {
//				echo "$i</br>";
//			}; 

		//// Disable MySQL
//			$out		= explode("\n", shell_exec("sudo /usr/share/webmin/virtual-server/disable-feature.pl --domain $ud_domain --mysql"));
//			foreach ($out as $i) {
//				echo "$i</br>";
//			}; 	

	}; // close if

}; // close if 

 

I think the code is quite easy to understand. If a check box is enabled install MySQL and phpMyAdmin. If it is unchecked then remove them. There are four parts, the install runs two commands and the uninstall runs two commands. Three of the commands are commented out as they work, I had to go through a process of elimination to work out which was the culprit and I narrowed it down to be the install of the phpMyAdmin script.

 

You can see from the commented line underneath, I used the echo to print the exact command running and if I run that on the server it completes fine. And the time it takes to run is:

 

$ time sudo /usr/share/webmin/virtual-server/install-script.pl --domain example.co.uk --version latest --type phpmyadmin --path /phpmyadmin/
Checking dependencies ..
.. done

Checking PHP version ..
.. done

Fetching required files ..
.. done

Configuring webserver PHP settings ..
.. already done.

Applying web server configuration ..
.. done

Now installing phpMyAdmin version 3.5.2.2 ..
phpMyAdmin installation complete. It can be accessed at http://example.co.uk/phpmyadmin//.
.. done

The initial administration login is example with the password xxxxxxxxxxx.

Applying web server configuration ..
.. done


real	0m10.860s
user	0m2.612s
sys	0m3.124s

 

Which should be easily quick enough for the script not to time out. Also the time it takes loading the page before it times out is longer than that anyway...

 

I have commented out all other code on the page, I am 100% sure it is this section causing the problem. And the really annoying thing is that I have already had this working correctly but due to a stupid error I removed the directory and had to restore from a backup in which I had not coded this yet...

 

Can anyone offer and pointers as to what could be causing it or a better way of coding what I am trying to achieve?

Link to comment
Share on other sites

Yup sudo is used in all of them. The other 3 are there but commented out because they work and I was narrowing which was at fault. Also in the second code block you can see the exact command running, it was generated from the echo command in the first code block (commented out and 'testing' comment') and I copied and pasted it onto a terminal. Except added the 'time' at the start to show how long the command took to run. and it was run as the user that the php is running as.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.