CN105677397B - Pass through the method for local gateway program optimization PHP far calls - Google Patents

Pass through the method for local gateway program optimization PHP far calls Download PDF

Info

Publication number
CN105677397B
CN105677397B CN201511026837.4A CN201511026837A CN105677397B CN 105677397 B CN105677397 B CN 105677397B CN 201511026837 A CN201511026837 A CN 201511026837A CN 105677397 B CN105677397 B CN 105677397B
Authority
CN
China
Prior art keywords
connection
php
gateway program
local gateway
message
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201511026837.4A
Other languages
Chinese (zh)
Other versions
CN105677397A (en
Inventor
张军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing Tu Niu Science And Technology Ltd
Original Assignee
Nanjing Tu Niu Science And Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing Tu Niu Science And Technology Ltd filed Critical Nanjing Tu Niu Science And Technology Ltd
Priority to CN201511026837.4A priority Critical patent/CN105677397B/en
Publication of CN105677397A publication Critical patent/CN105677397A/en
Application granted granted Critical
Publication of CN105677397B publication Critical patent/CN105677397B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Abstract

The invention discloses a kind of methods by local gateway program optimization PHP far calls, by increasing and local gateway program of the PHP server dispositions on same machine, the long connection between remote service is kept by local gateway program, PHP services the interprocess communication by the machine between local gateway program, then remote service is relayed to, to effectively improve performance using communication between local process, the expense that connection is created and closed in calling process is avoided by long connection, and connection is created and managed by connection pool, accomplish that connection number is controllable, connection is avoided excessively to cause remote server pressure, reach and completes far call within millisecond.

Description

Pass through the method for local gateway program optimization PHP far calls
Technical field
The invention belongs to PHP technical fields, and in particular to a kind of side by local gateway program optimization PHP far calls Method.
Background technology
The characteristics of PHP is a kind of general script of increasing income, and grammer absorbs C language, Java and Perl, is conducive to study, Using extensive, it is primarily adapted for use in Web development fields.With the dynamic page that PHP makes compared with other programming languages, PHP is Program is embedded into html document and goes to execute, execution efficiency is more many higher than the CGI for generating HTML markup completely;PHP may be used also To execute compiled code, compiling can reach encryption and Optimized code operation, make code operation faster, application is very extensive.
PHP equally also has the demand by network call remote service when realizing Web service end function.Example Such as, operating database increases, deletes, changes, looks into database, and message etc. is sent to message queue the inside.Under more common scene, such as Database interacts, and the C extensions that official is provided in PHP are supported, but in some special screnes, such as the communication with Kafka, it lacks Weary corresponding extension supports, it is necessary to oneself carry out far call.PHP remote invocation methods are usual under existing special screne There are two types of:
Method one:According to the communication protocol of service provider, the extension of PHP is developed using C language.But C language is opened It is larger to send out PHP extensions difficulty;And although C language execution efficiency is high, there is no long connection is realized, when remote service is called When frequency is very high, frequent establishment and closing connection increase calling duration.A new connection will be opened by calling each time, when When concurrent excessively high, very big pressure is caused to the available maximum number of connections of service side.
Method two:According to the communication protocol of service provider, directly realized using the socket of PHP.Due to PHP itself Execution efficiency it is poor, cannot be satisfied the calling demand under high-performance scene;In addition this method does not support long connection yet, frequently Establishment and close connection and increase calling duration, identical as method one, a new connection will be opened each time by calling, when simultaneously When sending out excessively high, very big pressure is caused to the available maximum number of connections of service side.
Obviously, the equal existing defects of existing two kinds of solutions, the interaction of they and Kafka substantially all in 10ms or more, It is also possible to longer, other than existing performance cannot meet us and require, when concurrent excessively high, it will usually ActiveMQ occur The phenomenon for connecting number deficiency, causes subsequent request to be unable to timely processing, to affect the execution time of interface.
Invention content
To solve the above problems, the invention discloses a kind of method by local gateway program optimization PHP far calls, Request performance can be promoted, while the quantity remotely connected can be reduced, the influence for avoiding remote service scarce capacity from bringing.
In order to achieve the above object, the present invention provides the following technical solutions:
A method of by local gateway program optimization PHP far calls, increase with PHP server dispositions at same Local gateway program on machine keeps the long connection between remote service, PHP services and local network by local gateway program By the interprocess communication of the machine between the program of pass, remote service is then relayed to, following steps are specifically included:
Step A starts gateway program:
Step A-1 monitors the Unix Domain Socket file paths configured in configuration file;
Step A-2 opens the thread of corresponding number according to the setting of configuration file, and local.sock is monitored to handle;
Step A-3 initializes connection pool, is connected with the long of remote service according to configuration file setting initialization is multiple;
Step B, PHP component and gateway program are communicated:
Step B-1 reads Unix Domain Socket file paths from configuration;
Step B-2 is created and is established Socket connections;
Step B-3, assembling need the message sent;
Character string is sent to gateway program by step B-4 by Socket;
Step B-5 closes Socket connections;
Step C, gateway program handle far call request:
Step C-1, the data of analysis request;
Step C-2 obtains a connection from connection pool, if not available connection, can create and return to a connection Object;
Step C-3 sends message by connection;
Connection is put into connection pool by step C-4, message after having sent, and keeps the connection created not close by connection pool.
Further, the step B-3 assemblings rule is:First trip is Topic titles, with multiple messages by newline " n " It is combined into a character string.
Further, the step C-1 resolution rules are:Using the first row as the title of Topic, all it is per a line later Need the message forwarded.
Further, the data resolution module defines when being communicated with Kafka using newline as each message Cut-off symbol, wherein the first row is the Topic titles of Kafka.
Further, the local gateway program includes NIO components, data resolution module, connection pool module, configuration management Module, the NIO components use Netty as its implementation, monitor the Unix Domain Socket files of the machine;Institute State the self-defined agreement of data processing of data resolution module;The connection pool module is for maintaining and managing long connection;It is described Configuration management module is used for centralized configuration variable element.
Compared with prior art, the invention has the advantages that and advantageous effect:
1. effectively improving performance using communication between local process, is avoided by long connection and create and close in calling process The expense of connection, and connection is created and managed by connection pool, accomplish that connection number is controllable, has avoided connection from excessively causing long-range Server stress reaches and completes far call within millisecond.
2. in such a way that Unix Domain Socket simplify interprocess communication, and can have very high performance.
3. passing through NIO frames so that gateway program itself is only needing few resources(Memory or CPU)In the case of can To handle per second ten thousand times or more requests.
Description of the drawings
Fig. 1 is flow chart of the present invention;
Fig. 2 is system structure of the invention figure;
Fig. 3 is the flow chart that PHP components and gateway program carry out communication steps;
Fig. 4 is the flow chart that gateway program handles far call request step.
Specific implementation mode
Technical solution provided by the invention is described in detail below with reference to specific embodiment, it should be understood that following specific Embodiment is only illustrative of the invention and is not intended to limit the scope of the invention.
Core of the invention thought is the service and long-range service in PHP(Such as Kafka)Between plus a local answer With --- i.e. local gateway program, the application and PHP server dispositions are kept and long-range clothes on same machine by the application Then long connection between business relays to remote service by the interprocess communication of the machine between PHP services and the application, As shown in Figure 1.
Realize the system architecture of the present invention as shown in Fig. 2, including:PHP components, local.sock, local gateway program, Middle PHP component packages pass through Unix Domain Socket and gateway program communication means;Local.sock is Unix Domain Socket files are used for interprocess communication.For calling Kafka, the structure of local gateway program includes NIO groups Part, data resolution module, connection pool module, configuration management module, NIO components use Netty as its implementation, monitor The Unix Domain Socket files of the machine;The self-defined agreement of data processing of data resolution module, for example, it is logical with Kafka Using relatively simple processing mode when letter, accorded with using newline as the cut-off of each message, wherein the first row is Kafka Topic titles, it is clear that need to define different data processing agreements when calling other remote services;Connection pool module is net Connection pool of the program based on the Apache Common Pool2 management Kafka Producer realized is closed, maintains and manages The long connection of Kafka Server;Configuration management module is realized reads configuration from the configuration file of YAML formats, and supports It defines and uses different configurations, some variable elements of centralized configuration under varying environment.
By the method for above-mentioned local gateway program optimization PHP far calls, include the following steps:
Step A starts gateway program:
Step A-1 monitors the Unix Domain Socket file paths that configure in configuration file, here acquiescence be/ var/local.sock;
Step A-2 opens the thread of corresponding number according to the setting of configuration file, and acquiescence is 10, is monitored to handle local.sock;
Step A-3 initializes connection pool, is connected with the long of remote service according to configuration file setting initialization is multiple.
Step B, PHP component and gateway program are communicated, and flow is as shown in Figure 3:
Step B-1 reads Unix Domain Socket file paths from configuration, and acquiescence is /var/ here local.sock;
Step B-2 is created and is established Socket connections, although having used Socket API here, due to PHP components and net Program is closed on same machine, therefore is directly communicated by system kernel, real data can't walk network layer;
Step B-3, assembling need the message that sends, and first trip is Topic titles, are combined by newline " n " with multiple messages At a character string.It is based on newline that Kafka, which calls the data protocol used, and first trip is destination name, later all per a line A data is represented, this benefit is can with streaming to handle the message of batch, reduces the expense of data parsing(Such as it is common JSON or XML just need entire message body all to get and can just parse).
Character string is sent to gateway program by step B-4 by Socket;
Step B-5 closes Socket connections.
Step C, gateway program handle far call request, and flow is as shown in Figure 4:
Step C-1, the data of analysis request are all later to need to forward per a line using the first row as the title of Topic Message;Different according to remote call service type, the specific resolving of this step can be varied from.
Step C-2 obtains a connection from connection pool, if not available connection, can create and return to a connection Object;
Step C-3 sends message by connection;
Connection is put into connection pool by step C-4, message after having sent, and keeps the connection created not close by connection pool.
Compared by pressure test, compared with previous solution, using the method for the present invention and Kafka communication when performance Promotion has 100 times, and the time per treatment, the connection number of remote service was also very low, net during overall operation all within 1 millisecond It is very low to close the CPU that program uses, not only increases efficiency, also reduces resource consumption, performance has very big promotion.
The technical means disclosed in the embodiments of the present invention is not limited only to the technological means disclosed in the above embodiment, further includes By the above technical characteristic arbitrarily the formed technical solution of combination.It should be pointed out that for those skilled in the art For, various improvements and modifications may be made without departing from the principle of the present invention, these improvements and modifications are also considered as Protection scope of the present invention.

Claims (6)

1. a kind of method by local gateway program optimization PHP far calls, it is characterised in that:Increase and PHP servers portion The local gateway program on same machine is affixed one's name to, the long connection between remote service, PHP clothes are kept by local gateway program By the interprocess communication of the machine between business and local gateway program, remote service is then relayed to, is included the following steps:
Step A starts gateway program:
Step A-1 monitors the Unix Domain Socket file paths configured in configuration file;
Step A-2 opens the thread of corresponding number according to the setting of configuration file, and local.sock is monitored to handle;
Step A-3 initializes connection pool, is connected with the long of remote service according to configuration file setting initialization is multiple;
Step B, PHP component and gateway program are communicated:
Step B-1 reads Unix Domain Socket file paths from configuration file;
Step B-2 is created and is established Socket connections;
Step B-3, assembling need the message sent;
Character string is sent to gateway program by step B-4 by Socket;
Step B-5 closes Socket connections;
Step C, gateway program handle far call request:
Step C-1, the data of analysis request;
Step C-2 obtains a connection from connection pool, if not available connection, can create and return to a connecting object;
Step C-3 sends message by connection;
Connection is put into connection pool by step C-4, message after having sent, and keeps the connection created not close by connection pool.
2. the method according to claim 1 by local gateway program optimization PHP far calls, it is characterised in that:Institute It is Kafka to state far call request.
3. the method according to claim 2 by local gateway program optimization PHP far calls, it is characterised in that:Institute Stating step B-3 assemblings rule is:First trip is Topic titles, and a character string is combined into multiple messages, adjacent two message it Between be attached using newline " n ".
4. the method according to claim 2 by local gateway program optimization PHP far calls, it is characterised in that:Institute Stating step C-1 resolution rules is:All it is later the message for needing to forward per a line using the first row as the title of Topic.
5. the method according to claim 1 by local gateway program optimization PHP far calls, it is characterised in that:Institute It includes NIO components, data resolution module, connection pool module, configuration management module to state local gateway program, and the NIO components make It uses Netty as its implementation, monitors the Unix Domain Socket files of the machine;The data resolution module is self-defined The agreement of data processing;The connection pool module is for maintaining and managing long connection;The configuration management module is for concentrating Configure variable element.
6. the method according to claim 5 by local gateway program optimization PHP far calls, it is characterised in that:Institute It states data resolution module to define when communicating with Kafka using newline as the cut-off of each message symbol, wherein the first row is The Topic titles of Kafka.
CN201511026837.4A 2015-12-30 2015-12-30 Pass through the method for local gateway program optimization PHP far calls Active CN105677397B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201511026837.4A CN105677397B (en) 2015-12-30 2015-12-30 Pass through the method for local gateway program optimization PHP far calls

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201511026837.4A CN105677397B (en) 2015-12-30 2015-12-30 Pass through the method for local gateway program optimization PHP far calls

Publications (2)

Publication Number Publication Date
CN105677397A CN105677397A (en) 2016-06-15
CN105677397B true CN105677397B (en) 2018-09-25

Family

ID=56298296

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201511026837.4A Active CN105677397B (en) 2015-12-30 2015-12-30 Pass through the method for local gateway program optimization PHP far calls

Country Status (1)

Country Link
CN (1) CN105677397B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106131205B (en) * 2016-07-29 2019-07-26 北京赛佰特科技有限公司 Big data information processing system and method for Internet of Things
CN108089933A (en) * 2017-12-29 2018-05-29 鸿之微科技(上海)股份有限公司 Call the method and system of calculation procedure in another system
CN108984316A (en) * 2018-06-15 2018-12-11 广州视源电子科技股份有限公司 It is a kind of for the method, apparatus of distributed data processing, electronic equipment and computer storage medium
CN108874567B (en) * 2018-07-19 2021-08-17 广州市创乐信息技术有限公司 Service processing method and system
CN110278278A (en) * 2019-06-26 2019-09-24 深圳市迅雷网络技术有限公司 A kind of data transmission method, system, device and computer media
CN112866393A (en) * 2021-01-26 2021-05-28 广州欢网科技有限责任公司 Method, device and system for data interaction between platforms
CN113010333B (en) * 2021-03-24 2021-10-15 北京中电兴发科技有限公司 Multi-scene inter-process communication method suitable for Linux server cluster

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1987864A (en) * 2006-12-31 2007-06-27 中国建设银行股份有限公司 Method and system for access data base
CN102833323A (en) * 2012-08-14 2012-12-19 新浪网技术(中国)有限公司 Method and system for remote control of controlled terminal by server
CN103699450A (en) * 2013-12-20 2014-04-02 国云科技股份有限公司 Linux adaptive component communication method
CN103795569A (en) * 2014-01-22 2014-05-14 亿赞普(北京)科技有限公司 Server connection method and device based on connection pool
CN104170353A (en) * 2013-12-27 2014-11-26 华为技术有限公司 TCP link configuring method, device and equipment

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040003085A1 (en) * 2002-06-26 2004-01-01 Joseph Paul G. Active application socket management

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1987864A (en) * 2006-12-31 2007-06-27 中国建设银行股份有限公司 Method and system for access data base
CN102833323A (en) * 2012-08-14 2012-12-19 新浪网技术(中国)有限公司 Method and system for remote control of controlled terminal by server
CN103699450A (en) * 2013-12-20 2014-04-02 国云科技股份有限公司 Linux adaptive component communication method
CN104170353A (en) * 2013-12-27 2014-11-26 华为技术有限公司 TCP link configuring method, device and equipment
CN103795569A (en) * 2014-01-22 2014-05-14 亿赞普(北京)科技有限公司 Server connection method and device based on connection pool

Also Published As

Publication number Publication date
CN105677397A (en) 2016-06-15

Similar Documents

Publication Publication Date Title
CN105677397B (en) Pass through the method for local gateway program optimization PHP far calls
JP5676655B2 (en) Mobile broadband device and method for managing mobile broadband device
WO2019029320A1 (en) Configuration management method, apparatus and device
CN107222324B (en) Service configuration method and device of network service
Pagurek et al. Integration of mobile agents with SNMP: Why and how
US20100281107A1 (en) Enterprise client-server system and methods of providing web application support through distributed emulation of websocket communications
EP3077907B1 (en) Management of network entity selection
CN101207568B (en) Multi protocol adapter and method for multi business to implement adapting treatment
CN103139051A (en) Instant messaging communication method based on Websocket protocol
CN103634138B (en) The remotely management of distributed scheduling and O&M method and system thereof
EP3837604A1 (en) In situ triggered function as a service within a service mesh
WO2014180407A1 (en) Pushing method and device therefor
Zhang et al. Performance evaluation of candidate protocol stack for service-based interfaces in 5g core network
CN111782259B (en) Reverse proxy-based microservice treatment method
CN112256246A (en) Micro-service integration framework for supporting cross-language calling in power system
US10740273B2 (en) Schema to ensure payload validity for communications on an asynchronous channel based bus
Corici et al. A solution for provisioning reliable M2M infrastructures using SDN and device management
Butterfield Fog computing with Go: A comparative study
CN105260179A (en) Method for achieving flex and servlet interaction
Lu et al. The next generation SDP architecture: Based on SOA and integrated with IMS
Kohler et al. ZeroSDN: A highly flexible and modular architecture for full-range network control distribution
JP2004520641A (en) Event bus architecture
Ostrowski et al. Storing and accessing live mashup content in the cloud
Hofer et al. Impact of the Application Layer Protocol on Energy Consumption, 4G Utilization and Performance
Tayur et al. Internet of things architectures: modeling and implementation challenges

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant