HI,

I am a newbie to PHP so I ask you to forgive my ignorance.

I am faced with the problem that my webhost disabled the exec() function and I got a script that uses the exec() function.

I would like to know how I could replace with an equivalent command that has the same effect.

For better understanding here is the part of code that I have to deal with:

if($oldvalue1==$newvalue1)
	{
		$output1 = exec("php update_butler.php >/dev/null &");
	}	

if($oldvalue==$newvalue)
{
	$output = exec("php update_records.php >/dev/null &");
}	

Basically I understand that this command ('exec()') shal execute the update_records.php. I hope there´s another way to execute this php file as I would have to find a webhost that provides exec() access.

Thank you very much and best regards,
MasterchiefCM

    You could simply [man]include[/man] the files, which would execute them as though their code was within your including script. They would not be launched as background processes (as the "&" does from the command line), however, if that is an issue. If you want to replicate sending any standard output to /dev/null, you could turn on output buffering then trash the buffer:

    ob_start();
    if($oldvalue1==$newvalue1)
        {
            include("update_butler.php");
        }    
    
    if($oldvalue==$newvalue)
    {
        include("update_records.php");
    }
    ob_end_clean();
    

      Thank you very much for your help NogDog.

      If you want to replicate sending any standard output to /dev/null, you could turn on output buffering then trash the buffer

      I am sorry but I don´t understand the meaning of this (please forgive a php newbie).

      Well I tried to solve the problem by just copy & pasting your given code into my script and as far as I can tell it executes the script but I get the following error as a response:

      Fatal error: Cannot redeclare begin() (previously declared in /users/comaxmedia/www/bay5/functions.php:5) in /users/comaxmedia/www/bay5/functions.php  on line 6

      I don´t understand this message and I would be glad if someone could explain it´s meaning to me (or even show me the solution).

      Thanks,
      MasterchiefCM

        Yeah, I can see how that might happen. Presumably each of those scripts defines a function named begin(). If you are running a PHP version >= 5.3.0, we might be able to do something with name-spaces to get around that. Otherwise, the first alternative that comex to mind would be to call the files via URL, e.g.:

        if($oldvalue1==$newvalue1)
            {
                $output1 = file_get_contents("http://localhost/path/to/update_butler.php");
            }    
        
        if($oldvalue==$newvalue)
        {
            $output = file_get_contents("http://localhost/path/to/update_records.php");
        }
        

          i would just move hosts myself there are lots of them, and if exec is disabled, what else may be.

            Thank you very much NogDog and dagon.

            @

            I tried your solution but from the output I guess that the file_get_contents
            function is also disabled.

            Here´s the output:

            Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /users/comaxmedia/www/bay5/checkupdate.php on line 47
            
            Warning: file_get_contents(http://comaxmedia.bplaced.net/bay5/checkupdatebutler.php) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /users/comaxmedia/www/bay5/checkupdate.php on line 47
            
            Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /users/comaxmedia/www/bay5/checkupdate.php on line 54
            
            Warning: file_get_contents(http://comaxmedia.bplaced.net/bay5/checkupdaterecords.php) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /users/comaxmedia/www/bay5/checkupdate.php on line 54

            Please tell me if I made something wrong but I guess bplaced just disabled every function I need to get this script running.

            @

            I may consider to move to another host. Could you tell me which host have exec() and all the other function enabled and how much that would cost (I don´t guess there will be free webhost providing these functions enabled)?

              No, they have apparently also disabled the allow_url_fopen option for the same sort of security reasoning. You could use the [man]cURL[/man] extension to call those files, though it gets a bit more intricate (not rocket science, but more steps and details).

              If it were my site, I'd be editing the files so that I could include them, rather than trying to run them externally in any manner. In this case, you might just be able to rename the functions in one of the files with some sort of prefix or suffix to the function name, then make sure you use the same naming anywhere where that function is called within that file.

                As you may guess I am not familiar with cURL too:p

                Well I just tried to copy and paste the code of checkupdatebutler.php and checkupdaterecords.php into checkupdate.php to get rid of the errors.

                (I know that this won´t work with further editing but I just wanted to give it a try and this is the output:

                Fatal error: Cannot redeclare SendHTMLMail2() (previously declared in /users/comaxmedia/www/bay5/functions.php:17) in /users/comaxmedia/www/bay5/checkupdate.php  on line 47

                Well I would post the code of checkupdate.php but I guess it´s a littlebit too long as the file contains 200 lines of code.

                  It is possible that both (all) definitions of SendHTMLMail2() are identical. If so, just remove one of them. The function definition is

                  function SendHTMLMail2(argument list) {
                  # function body, ending with
                  }

                    Thank you very much for your help johanafm.

                    I tried your hint and compared the two functions: They are identical, as you suggested I removed one of them entirely and this was the first output:

                    Parse error: syntax error, unexpected '}' in /users/comaxmedia/www/bay5/checkupdate.php  on line 141

                    As the error tells there was an syntax error because of a '}'. Well I deleted this one aswell and this is the output I get now, after 2 minutes of loading and waiting:

                    Internal Server Error, code 500

                    Well now I am confused😕:rolleyes:

                    I would really appreciate any kind of help as I really don´t have a clue what´s going on by now!

                      MasterchiefCM;10957609 wrote:

                      I may consider to move to another host. Could you tell me which host have exec() and all the other function enabled and how much that would cost (I don´t guess there will be free webhost providing these functions enabled)?

                      There are no free lunches, you are seeing the down side of using a free host.

                        5 days later

                        Thanks dagon,

                        Well I won´t give it another try, maybe I will pay a company to rewrite and install this script correctly. Nevertheless thanks everybody for your help!

                        Cheers!

                          Write a Reply...