PHP MySQLi Singleton for Ajax Requests Ends with Many Processes

I have a PHP application that uses AJAX to retrieve information - in reverse, it uses the PHP single MySQLi of the same name. AJAX requests are sent every 0.5 seconds and they read some data from the database and deliver it as a JSON String to the website. When I open the website several times (on different tabs), I get an error because PHP, or rather apache, could not "fork another process." There is enough RAM on my server, but the problem is that the process limit of 130 processes has been reached.

cat /proc/user_beancounters
---------------------------
        | held  | maxheld |
numproc |  130  |     130 |

So, I would like to know if it is possible that a singleton is a mistake (for example, “why are singles bad”) or could you imagine a different source of errors? The source of the error is that so many MySQL processes start and peak. restriction?

0
source share
4 answers

I would recommend you publish your singleton and ajax-back-end code. It's hard to make an expression that says your singleton or ajax back-end is to blame if we cannot consider it.

, , . , , 0,5 . , , . , SQLi , , 0,5 .

ajax? ? php? - ? . , . , , ajax. , , php , .

( PHP ), . , ajax. ajax, . , . , , , , , 0,5 .

!

+1

, 0,5 , , , , , (), . , , Comet.

, , , , , , .

+1

, ( ), - , . ? (, ) .

- , . , , . , - . APE (Ajax Push Engine - http://www.ape-project.org/).

, . , , . .

+1

, ...

When the AJAX-Request is processed, a new PHP process starts; singleton is available only in this process, single games are not shared among several PHP processes. Thus, each request ends with its own connection to the database, singleton simply guarantees that there is no more than one connection for each process.

You might want to take a look at persistent connections, although I prefer not to use them; and I'm not sure if they are available with MySQLi at all.

-1
source

All Articles