简体   繁体   中英

PHP long-polling with .txt-File instead of a MySQL Database

I want to implement a simple long polling system in PHP. A simple Szenario:

The Project is based on two websites. Website A and Website B. There are two Users. One on Website A (UserA) and one on Website B (UserB). On the Website A is a Button. If UserA push the Button, the color of Website B change instantly.

Of course i can do this with a MySQL Database, but this seems way to big, because i just want to transfer one Bit.

Are there any other oppurtinitys to store one Bit on the Server an have acces from all PHP Pages, which are hosted on the Server?

I thought i could use a simple .txt file, but i am not shure if the Server Crushes if two diffrent Websites want to access to the same file. Is this a problem?

Or have you any other Ideas how to resolve it?

I would not recommend using a text file, since I/O operations is pretty slow compared to other methods.

You have to read the file on every page load/refresh or even worse, with an ajax request to do it instant. I think I would recommend something like Redis / Memcached and make some sort of ajax call to read from that (if you want it to be instant).

If you don't have access to the server, to install that kind of software, I would use a MySQL database.

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM