views:

120

answers:

2

Is there any way to make a PDO object throw an error if a query takes too long? I have tried PDO::ATTR_TIMEOUT to no effect.

I'd like a way to have a query throw an error if it is running for longer than a certain amount of time. This is not something that I can do in the database, ie, no maintenance jobs running on the db or anything.

+2  A: 

I'm not sure if you can do this in Oracle but I'm going to say it's not possible to do this within PHP since PHP is issuing the query to Oracle to be run and then is waiting for Oracle's response back. It may be possible to modify the PDO extension to support this, but you would need to modify the extension code (the actual C code) as there probably isn't any way to do this in just PHP.

Steven Surowiec
+3  A: 

I'm not sure what you mean by "This is not something that I can do in the database", but I would suggest that you have the person administering the database set up an Oracle profile to limit this on the database side. There are parameters such as CPU_PER_CALL and LOGICAL_READS_PER_CALL that can cap queries. The profile can be applied only to specific users if desired.

dpbradley
It's not long queries in general I want to stop, but just this one that is used for monitoring the database.
Brian Ramsay
Ah, I see. Well, if there's no client-side solution, a somewhat convoluted approach with profiles would be to reconfigure the application so that this query is only issued by a specific user and then apply the profile to only that user.
dpbradley