in reply to How to Limit MySql Execution Time?

How about using the mysql command line tool with --quick --raw -be options via a piped open?

my $sql = ...; my $cmd = qq[mysql --quick --raw -u $user -p$pass -be $sql] my @results; eval{ alarm 5; my $pid = open SQL, "$cmd |" or die $!; push @results, <SQL>; alarm 0; }; if( $@ ) { } ...

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: How to Limit MySql Execution Time?
by aceofspace (Acolyte) on Dec 21, 2010 at 12:42 UTC
    Thanks for your reply. But I've a hard time understanding your code and how to implement it.

    Please do me a flavor. Kindly edit my original script below with your implementation.
    #!/usr/bin/perl require 'myconfigure.cgi'; $timeout = 5; use DBI; $keywords = "Whether rocking natural-curls, a-short"; print "Content-type: text/html\n\n"; sub do_search { $time1 = time; $dbh=DBI->connect("dbi:mysql:$database:localhost","$username","$pa +ssword"); $keywords_quoted = $dbh ->quote ($keywords); $query="SELECT count(*) FROM $websites_table WHERE MATCH(title) AG +AINST ($keywords_quoted)"; $sth=$dbh->prepare(qq{$query}); $sth->execute(); $total_count = $sth->fetchrow_array (); $sth->finish; $dbh->disconnect ||die("Couldn't disconnect to database!\n"); $time2 = time; $time_ran = $time2 - $time1; } eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; &do_search; alarm 0; }; if($@) { $time2 = time; $time_ran = $time2 - $time1; print "$@, Time Ran: $time_ran, Total Count: $total_count\n"; exit; } print "Time Ran: $time_ran, Total Count: $total_count\n"; exit;

    Thanks so much!

      Did you follow the supplied link to the mysql documentation?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Yes, I did.

        But that document is for running MySql from Shell, a command tool operation. I'm running MySql from script. Have no idea how to convert the MySql commands into scripting environment.

        You've shown a script how to do it:
        my $sql = ...; my $cmd = qq[mysql --quick --raw -u $user -p$pass -be $sql] my @results; eval{ alarm 5; my $pid = open SQL, "$cmd |" or die $!; push @results, <SQL>; alarm 0; }; if( $@ ) { }

        I don't understand some of your commands and how to implement them into my script.

        You bought up this solution of using MySql command tool to limit MySql execution time in reply to my query. You have obviously seen my script. It will help if you can edit my script to show me how to implement the solution that you suggested.

        Thanks so much.