Send message to another PHP file

Is it possible for one PHP file to send a “message” to certain users in another PHP file?

Note that the “message” should be able to receive a PHP file that is already running, so simply accessing other files does not matter. The image below shows what I want to do:

Enter image description here

In this example, user 1 calls "send.php", which subsequently sends a message to the "receive.php" instances of users 1,2 and 4. Is this possible?

Additional Information

I can not register messages in a central place, for example, in a file or database, because in the end I get requests for messages approximately every 100 Moscow time, which is likely to overload the database / file system. I need it to be instant.

In addition, I cannot use sessions or cookies because, as mentioned, the message needs to be sent to multiple users. Finally, the resulting PHP file does not end until the user leaves the page (this is really an HTML5 eventsource file).

+4
source share
4 answers

You can save data through pages using sessions or database .

0
source

Additional information: I can not register messages in a central place as a file or database, because I receive requests for messages approximately every 100 ms, which is likely to overload the database / file system. I need it to be instant.

This can be done, but it is not in best practices. You can create a separate file for each message. This is a very bad practice.

In terms of your problem with a centralized database, you never know. It can handle your requests, just try and find out.

No programmers have coped with the first attempt. They tried something new and were wrong ... Everyone makes mistakes in terms of finding the best approach to the application.

0
source

Well, there may be ways that are much easier, but try using a message broker with pub-sub features (called topics in the JMS world). They are designed specifically for the fast and reliable transfer of large volumes of messages from servers to clients.

An easy way to create a test system for such an installation can be to use STOMP , a capable message broker (see here for a list of available solutions) and combine this with the PHP STOMP client (the list is available on the same page.

Be sure to read this note about long-term subscriptions : since your PHP scripts will most likely not work at the time the message requires a function that emulates a long-term subscription. I do not know all the brokers described on the page mentioned above, but ActiveMQ , and it has been quite a long time, and has a very good reputation.

0
source

PHP is not working. It runs a script and exits. You need to search for a session or use a database. If you want a fantasy, use jQuery and Ajax.

-1
source

All Articles