1

I'm having a web application written in PHP.

One function of this application is a document archive which is a MySQL database on another server. And this archive server is pretty unreliable performance wise, but not under my control. The archive server has got often long table locks often, which results in getting a connection, but not getting any data.

This often leads to open MySQL connections which saturate the resources of the web-application server. As a result the whole web application becomes slow/inacessible.

I would like to decouple the two systems.

I thought the logical way would be for my PHP application to abort a SELECT query if it takes longer than 1 or 2 Seconds to free up resources and present the user with a message that the remote system is not responding in time.

But how is it best to implement such a solution?


UPDATE: the set_time_limit() option looks Promising. but not fully satisfying as im not able to present the user with an "message" but at least it might help to prevent the saturation of the Resources.

Community
  • 1
  • 1
wolffc
  • 114
  • 4
  • You can't do that. You can try something with the mysql configuration, but you already said, you can't controll the server. – colburton Jun 24 '14 at 14:54
  • possible duplicate of [Limit execution time of an function or command PHP](http://stackoverflow.com/questions/1176497/limit-execution-time-of-an-function-or-command-php) – Daniel Jun 24 '14 at 14:59

2 Answers2

1

I think you should use maximum execution limit function provided in php.

stacky
  • 108
  • 1
  • 15
0

You can set MySQL time out like this

Or you can set it on code like this

I think second solution might be better for you Then if the timeout error raised, you can tell the server not responded

user3309301
  • 301
  • 1
  • 4