I have a rest service in Apache - PHP that triggers a database query and data processing.
REST -> DB_QUERY.
Problems comes when REST incomming are too much and each one triggers a new thread of DB_QUERY.
REST -> DB_QUERY -- thread 1
REST -> DB_QUERY -- thread 2
REST -> DB_QUERY -- thread 3
REST -> DB_QUERY -- thread ...
The solution I need is have only one DB_QUERY in process.
I could do it by two ways:
1 - Break the trigger, and set a bucle in the DB_QUERY process (while true).
REST -- thread 1
REST -- thread 2
REST -- thread 3
REST -- thread ...
DB_QUERY(while true)
2 - Maintain the trigger, but have only one DB_QUERY.
REST -- thread 1 |
REST -- thread 2 |
REST -- thread 3 |
REST -- thread ...|___> DB_QUERY
For the first solution, I don't know how to launch a the DB_QUERY(while true) in a clean way. I have done it with systemctl daemon, but I would prefer to trigger it from php code.
For the second one I have tried singleton patter, but it doesn't work because DB_QUERY is triggered from differents threads.