Home >Backend Development >PHP Tutorial >Some issues regarding the WeChat public account receiving data and transmitting it to the LAN website

Some issues regarding the WeChat public account receiving data and transmitting it to the LAN website

WBOY
WBOYOriginal
2016-08-18 09:16:011293browse

I just want to find some ideas and listen to the opinions of experts. I don’t ask others to help me make detailed plans, I just want to point out the direction of research. I know PHP/Java and can write a little Python compared to Baidu.
In the local LAN, there is a server running a php website. This server is in a deep intranet (dynamic public IP + network management does not do port forwarding); there is another server in the computer room of xx cloud, with an independent Public IP, running php to connect with WeChat. Now I want to create a function that allows the information sent by WeChat to be forwarded to the server in the LAN through the xx cloud host. The xx cloud host is a Linux operating system, which can be used to run PHP/Python/Java; the LAN host is an ordinary PC with a windows operating system, which can run PHP/Python/Java. Both hosts are equipped with MySQL databases (also this question The selected database). I wonder if you have any more subtle ideas. .
Now I have a few preliminary ideas, and I would like your comments, thank you!
1. WeChat->Cloud Host (PHP)->Database
The local area network uses Python or Java to poll to obtain new data to the local database.
2. WeChat -> Cloud Host (PHP) -> Cross-process transmission to the Socket server written in Python
The local area network uses Python or Java to establish a Socket link with the cloud host, and the real-time communication is stored in the database.
3. WeChat->Cloud Host (PHP)->Database.
The local database and the remote database are created to synchronize the master-slave database (the key is that the remote can only write without checking)
4. WeChat->Cloud Host (PHP) -& gt; Database t Local writing program directly connects two databases to do some operations. .
The above are some of the results of my thinking on this issue. I feel that each method will affect the speed and efficiency of the overall system.

Reply content:

I just want to find some ideas and listen to the opinions of experts. I don’t ask others to help me make detailed plans, I just want to point out the direction of research. I know PHP/Java and can write a little Python compared to Baidu.

In the local LAN, there is a server running a php website. This server is in a deep intranet (dynamic public IP + network management does not do port forwarding); there is another server in the computer room of xx cloud, with an independent Public IP, run php to connect with WeChat. Now I want to create a function that allows the information sent by WeChat to be forwarded to the server in the LAN through the xx cloud host. The xx cloud host is a Linux operating system, which can be used to run PHP/Python/Java; the LAN host is an ordinary PC with a windows operating system, which can run PHP/Python/Java. Both hosts are equipped with MySQL databases (also this question The selected database). I wonder if you have any more subtle ideas. .
Now I have a few preliminary ideas, and I would like your comments, thank you!
1. WeChat->Cloud Host (PHP)->Database
The local area network uses Python or Java to poll to obtain new data to the local database.
2. WeChat -> Cloud Host (PHP) -> Cross-process transmission to the Socket server written in Python
The local area network uses Python or Java to establish a Socket link with the cloud host, and the real-time communication is stored in the database.
3. WeChat->Cloud Host (PHP)->Database.
The local database and the remote database are created to synchronize the master-slave database (the key is that the remote can only write without checking)
4. WeChat->Cloud Host (PHP) ->Database
          Write a program locally to directly connect the two databases to perform some operations. .
The above are some of the results of my thinking on this issue. I feel that each method will affect the speed and efficiency of the overall system.

You can use the subscription/publishing function of redis, and messages can be delivered instantly

Let me add thickness to your second idea

WeChat->Cloud Host (PHP)->Start a rabbitMQ message queue server, throw the WeChat message into the queue->The LAN host starts a rabbitMQ client, retrieve the message from the server->Throw it into the database

The entire message transmission process is carried out asynchronously, and there will be no blockage in any link. It is done properly and there is no need to reinvent the wheel

There are many options, just like 1, 2, 3, and 4 you gave yourself. At this time, it depends on the business scenario:

  1. Are you pressed for time?

  2. Is the data volume large?

  3. Are the latency requirements high?

  4. How is the concurrency?

  5. Is there any limit on hardware and software investment?

Can’t you use peanut shells

These 4 solutions are all feasible in theory. But remember to pay attention to these points in actual scenarios:
1. All your solutions are write operations. If there are read operations, some solutions will be difficult to handle. If you rely on asynchronous polling, there will definitely be data inconsistency. 2. If you maintain a long connection for communication, if there is no data in a short period of time, will the firewall click off your link? This is a
very difficult and very commonbig problem, especially under the terrible premise that the network management does not provide port forwarding. 3. Regarding option 4, will your network delay cause zombies or dirty data to user operations?

China’s network quality is very poor, try to avoid multiple remote servers processing a linear operation, and try to avoid long remote connections.

Generally, when setting up a WeChat server in a local area network, port forwarding is used (if it is a dynamic IP, a dynamic domain name must be configured). Now your PHP server does not process business in essence, but only acts as a proxy. Then I have two options. 1. Build nginx on the public server and use dynamic domain name technology to reverse proxy to your LAN server. 2. Use the service middle Price, such as java's dubbo, can remotely call services in the local area network from the external server

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn