CN116136787A - Method and device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script - Google Patents
Method and device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script Download PDFInfo
- Publication number
- CN116136787A CN116136787A CN202310294655.3A CN202310294655A CN116136787A CN 116136787 A CN116136787 A CN 116136787A CN 202310294655 A CN202310294655 A CN 202310294655A CN 116136787 A CN116136787 A CN 116136787A
- Authority
- CN
- China
- Prior art keywords
- php
- golang
- script
- execution
- embedded
- 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.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45504—Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
- G06F9/45508—Runtime interpretation or emulation, e g. emulator loops, bytecode interpretation
- G06F9/45512—Command shells
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Stored Programmes (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
The invention discloses a method and a device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script, wherein the method comprises the following steps: step S1, when compiling PHP, enabling an embedded module to generate a dynamic library or a static library required by PHP embedded SAPI call; s2, packaging PHP embedded SAPI; s3, constructing a Golang package, starting cgo, and packaging an embedded execution inlet of a single PHP script; s4, packaging batch execution inlets, traversing the scripts input by the input, calling a single embedded execution inlet in Goroutine, and executing concurrently; and S5, calling the encapsulated Golang package in the Golang service code, and executing the incoming PHP script concurrently.
Description
Technical Field
The invention relates to the technical field of Web development and Internet, in particular to a method and a device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script.
Background
In the current internet technology and Web development, golang (Go, also called Golang, is a static strong type and compiled language developed by Robert Griesemer, rob Pike and Ken Thompson of Google), go language grammar is similar to C, and is provided with memory security, GC (garbage collection), structural morphology and CSP-style concurrent computation function), and PHP are two commonly used development languages. PHP is a weak type explanatory language, is widely used for Web development due to the characteristics of easy operation, expandability and the like and good community support, but in Web development, a certain time-consuming task needs to be put into a background for processing, and because PHP script does not reside in a memory originally, the PHP script is often dependent on other approaches to realize task scheduling.
Because the business logic is basically realized by PHP, most tasks are scheduled by PHP CLI mode, when the number of tasks is large, the execution time is uncertain, and the timeliness requirement is also provided for the task execution result, the CLI is started in batch at the same time to execute PHP scripts, so that a large number of processes are generated, the CPU utilization rate of the system is increased, the memory occupation is increased, the overall load is increased rapidly, and the system is seriously disabled; often, the script task has long running time and is not easy to find when the problem is checked.
On the other hand, golang's compact design, native supports concurrent programming, making concurrent programming very simple. Coroutine, like threads, shares stacks, does not share stacks, and switching of coroutines is typically explicitly controlled in code by a programmer. The method avoids extra consumption of context switching, gives consideration to the advantages of multithreading, and simplifies the complexity of high concurrence programs. The Golang language carries out native support on the language layer facing the cooperative program and is called golutin, golang encapsulates and processes the golutin dispatch in multiple aspects such as run, system call and the like, and is managed by the go runtime (run) to a certain extent, when a certain golutin is blocked, a CPU is given out to other golutin, so that if Golang can be combined with PHP, the execution efficiency of PHP script can be improved.
Disclosure of Invention
In order to overcome the defects in the prior art, the invention aims to provide a method and a device for improving the execution efficiency based on Golang protocol Cheng Qianru PHP script, so as to embed the PHP script execution capacity based on Golang and realize the purpose of improving the PHP script execution efficiency by using Goroutine.
In order to achieve the above purpose, the invention provides a method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script, comprising the following steps:
step S1, when compiling PHP, enabling an embedded module to generate a dynamic library or a static library required by PHP embedded SAPI call;
s2, packaging the PHP embedded SAPI by using a C language to generate a C language code file for packaging and calling;
s3, constructing a Golang package, starting cgo, and further packaging an embedded execution entry of a single PHP script packaged by a C language;
s4, packaging batch execution inlets, traversing the scripts input by the input, calling a single embedded execution inlet in Goroutine, and executing concurrently;
and S5, calling the Golang package packaged in the step S3 in the Golang service code according to the implementation requirement, and executing the incoming PHP script concurrently.
Preferably, step S1 further comprises:
step S100, acquiring and decompressing PHP source codes of a target version;
step S101, entering into a decompressed source code catalog, and operating/configuration to enable Embedded;
step S102, executing make and make install, generating a dynamic library, and installing the dynamic library into a dynamic library catalog.
Preferably, step S2 further comprises:
step S200, newly creating php_end_exec.c and php_end_exec.h files for packaging the C file and the corresponding header file of the PHP embedded SAPI;
step S201, introducing # include 'sapi/emubed/php_emubed.h' into a php_emud_exec.h file;
step S202, packaging PHP embedded SAPI by using php_end_exec.c, implementing a method for embedding and executing PHP script, and determining an embedded and executed entry execution_php of the PHP script.
Preferably, in step S202, an initialization operation of the PHP framework is performed, the php_execution_script of the SAPI execution script is called to implement embedding and executing the PHP script, and the closing and recovering resource ending operation of the PHP framework is completed after the php_execution_script method is executed.
Preferably, step S3 further comprises:
step S300, newly creating a Golang package named php, creating a php folder, and newly creating an emmbedExec. Go under the php directory;
step S301, enabling Golang cgo in the emmbedExec. Go to call the C language code file packaged in step S2;
step S302, adding # cgo related compiling FLAGS into the emmbedExec. Go, and introducing a c-header file php_emmbed_exec.h;
step S303, calling the script execution capability of the PHP embedded SAPI package in the C language in the step S2, and realizing the embedded execution of the entry of the single PHP script in the EMbedExec.
Preferably, in step S301, import "C" in emmbedexec.go enables cgo to call the C language code file encapsulated in step S2.
Preferably, step S4 further comprises:
step S400, adding a batch execution inlet MultiExec ([ ] files) into the emmbedExec. Go, taking into account each structural body slice, and receiving execution scripts with variable length;
step S401, traversing the incoming files, embedding and executing each file in Goroute, and calling the single script executing method packaged in step S3.
Preferably, step S5 further comprises:
step S500, importing the Golang packet generated in the step S3 into a service logic code;
step S501, php.Exec is called at the place where the PHP library is required to be called or a single script is executed, and relevant optional parameters are transmitted in;
step S502, calling php.MultiExec at a place where a plurality of PHP scripts are required to be executed concurrently;
step S503, compiling and generating an executable file and running, and embedding and executing PHP scripts according to business logic.
Preferably, a Zend virtual machine is embedded in the Golang program to realize interaction with the PHP program.
In order to achieve the above objective, the present invention further provides a device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script, comprising:
the PHP script compiling module is used for starting the embedded module when compiling the PHP script and generating a dynamic library or a static library required by PHP embedded SAPI call;
the PHP embedded SAPI packaging module is used for packaging the PHP embedded SAPI by using a C language to generate a C language code file for packaging and calling;
the Golang package construction module is used for constructing a Golang package, starting cgo and further packaging an embedded execution entry of a single PHP script packaged by a C language;
the single embedded execution entry calling module is used for packaging batch execution entries, traversing the scripts input by the input, calling the single embedded execution entry in Goroute and executing concurrently;
and the service code calling execution module is used for calling the Golang package packaged by the Golang package construction module in the Golang service code according to the implementation requirement and concurrently executing the incoming PHP script.
Compared with the prior art, the method and the device for improving the execution efficiency based on the Golang protocol Cheng Qianru PHP script are based on the capability of executing the PHP script by Golang embedding, and achieve the aim of improving the execution efficiency of the PHP script by using the Goroutine; compared with the traditional PHP CLI mode, the invention does not need external programs or scripts to realize the scheduling of script tasks, and the invention does not generate a large number of processes when the PHP scripts are executed in batches and concurrently, thereby greatly reducing the system scheduling and the consumption of CPU caused by context switching; meanwhile, under the Goroute scheduling mechanism of Golang, concurrency performance is greatly improved, and PHP script concurrency execution efficiency is improved.
Drawings
FIG. 1 is a flow chart of steps of a method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to the present invention;
FIG. 2 is a system architecture diagram of a device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to the present invention;
FIG. 3 is a flowchart of a method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script in an embodiment of the invention.
Description of the embodiments
Other advantages and effects of the present invention will become readily apparent to those skilled in the art from the following disclosure, when considered in light of the accompanying drawings, by describing embodiments of the present invention with specific embodiments thereof. The invention may be practiced or carried out in other embodiments and details within the scope and range of equivalents of the various features and advantages of the invention.
The SAPI is Server Application Programming Interface, namely a server side application programming port, the PHP SAPI is an interface for interaction between the PHP and other applications, the PHP provides a plurality of SAPIs, and the implementation methods are as follows: cgi, DLL of fast-cgi, cli, isapi, apache module, embedded; wherein the embedded SAPI causes the PHP to be embedded in other programs, and calls an API provided by the PHP in the other programs to execute the PHP code segment or the PHP script file; if the third party program wants to use PHP, then the SAPI is needed to be a common library file after compiling (the common library file can be compiled into a static library or a shared library), so the invention combines the characteristics of two languages to achieve the aim of improving the execution efficiency based on Golang protocol Cheng Qianru PHP script.
FIG. 1 is a flow chart of steps of a method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script. As shown in FIG. 1, the method for improving the execution efficiency based on Golang protocol Cheng Qianru PHP script can embed a ZendVM (Zend virtual machine) in the Golang program to realize interaction with the PHP program, and comprises the following steps:
step S1, a PHP is used as a library to be installed depending on an Ebed module of a PHP official; when compiling PHP, the Ebed module is started to generate dynamic library or static library required by Ebed SAPI call. In the invention, the PHP of the target version is acquired for compiling, and the PHP can be compiled by instructions: configuration-enabled-end, enable end, compile completion generate PHP Ebed SAPI (PHP provides one of SAPI, allow PHP/ZEND provided functions to be called in other languages, the Ebed's implementation logic encapsulates only several processing functions of PHP lifecycle, APIs providing operability externally such as php_end_init, php_end_short_down, etc. call required libpep. So (dynamic library) or la/. Lib (static library)
Specifically, step S1 further includes:
step S100, acquiring and decompressing the PHP source code of the target version, for example, downloading and decompressing the PHP source code of the target version, for example, PHP7.3.16, decompressing the source code file by using a tar or decompression tool;
step S101, entering into a decompressed source code catalog, running/configuration (the source code contains configuration files for compiling configuration, environment inspection and the like), and designating-enable-end= [ shared|static ] to enable an Embedded module; it should be noted that, for-enable-end= [ shared|static ] the library type may be specified, where-enable-end represents the specification, shared represents the dynamic state, static represents the static state, and the implementation may be arbitrarily selected, in the embodiment of the present invention, a dynamic library is described as an example, that is, the specification-enable-end=shared to enable the embedded module, because the size of the executable file generated by using the dynamic library may be slightly smaller.
Step S102, executing make and make install, generating libppp 7.So, and installing (copying) to the dynamic library catalogue;
and S2, packaging the PHP embedded SAPI by using a C language to generate a C language code file for packaging calling, and calling in a subsequent Golang.
Specifically, step S2 further includes:
step S200, newly creating php_end_exec.c and php_end_exec.h files (the code file name of C packaged PHP SAPI) for packaging the C file and the corresponding header file of PHP embedded SAPI;
step S201, introducing a # include 'SAPI/emud/php_emud.h' in the php_emud_exec.h file, wherein SAPI/emud/php_emud.h defines the declaration of PHP emud SAPI to an external interface;
step S202, implementing PHP-embedded SAPI encapsulation in php_encapsulated_exec.c: performing initialization operation of the PHP framework, calling a method php_execution_script of the SAPI execution script to realize embedding and executing the PHP script, and completing ending work such as closing recovery resources of the PHP framework after executing the php_execution_script method; the embedded execution method entry of the PHP script is defined as execution_php.
Step S3, constructing a Golang package, enabling cgo, and further packaging an embedded execution entry of a single PHP script packaged by a C language: exec (filename, argc, argv).
Specifically, step S3 further includes:
step S300, newly creating a Golang package named PHP, and newly creating a PHP folder, and newly creating an embedExec. Go under the PHP directory to be used for storing codes of PHP script execution entries of Golang further package C package (namely php_embed_Exec. C and php_embed_exec. H of step S2); that is, the invention performs secondary encapsulation on the encapsulated C language code file through the emmbedExec.go, and the method interface in the Golang package can be directly called in the subsequent Golang service code.
Step S301, golang cgo (Golang is self-contained and can support interworking with the C language interface after opening) is started in the emmbedExec. Go to call the C code in step S2. In a specific embodiment of the present invention, import "C" enables cgo in EMbedExec. Go to invoke the encapsulated C language code file in step S2.
Step S302, adding # cgo related compiling FLAGS in the emmedExec. Go, and introducing a c-header file php_emmedExec. H.
Step S303, calling the script execution capability of the PHP embedded SAPI package in the C language in the step S2, and implementing the embedded execution of the entry of the single PHP script in the emmbedExec. Exec (filename, argc, argv).
And S4, packaging batch execution inlets, traversing the scripts input by the input, calling a single embedded execution inlet in Goroute, and executing concurrently, so that the execution of single and multiple scripts is finally supported. The entry of the single script execution is implemented in step S3: exec (filename, argc, argv), the entry method of the step of executing a plurality of scripts is implemented based on the entry of the single script execution, namely, multi Exec ([ (] files).
Specifically, step S4 further includes:
step S400, adding a batch execution entry MultiExec ([ ] files) into the emmbedExec. Go, wherein the joining is slicing of each structure body, and receiving execution scripts with variable length;
step S401, traversing the incoming files, embedding and executing each file in Goroute, and calling the single script executing method packaged in step S3: go func () { Exec (filename, argc, argv) }.
And step S5, calling a step S3 package Golang package (named PHP, and a main implementation code file of EMbedExec. Go) in the Golang service code according to the implementation requirement, and concurrently executing the incoming PHP script.
Specifically, step S5 further includes:
in step S500, golang packet, import "php", is generated by importing S3 into service logic code.
Step S501, php.Exec is called at the place where the PHP library is required to be called or a single script is executed, and relevant optional parameters are transmitted in;
step S502, calling php.MultiExec at a place where a plurality of PHP scripts are required to be executed concurrently;
step S503, compiling and generating an executable file and running, and embedding and executing PHP scripts according to business logic.
FIG. 2 is a system architecture diagram of a device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to the present invention. As shown in FIG. 2, the device for improving the execution efficiency based on Golang protocol Cheng Qianru PHP script of the invention comprises:
the PHP script compiling module 201 is used for relying on an Ebed module of the PHP official to realize that PHP is used as a library to be installed; when compiling PHP, the Ebed module is started to generate dynamic library or static library required by Ebed SAPI call. In the invention, the PHP script of the target version is acquired for compiling, and the PHP can be compiled by instructions: configured-enabled-end, enable Ebed module, compile completion generate PHP-Ebed SAPI (PHP provides one of SAPI, allow PHP/ZEND provided function to be called in other languages, the implemented logic of Ebed only encapsulates several processing functions of PHP lifecycle, API providing operability for external such as php_end_init, php_end_short_down, etc. call required libpep.so (dynamic library) or. La/. Lib (static library)
The PHP script compiling module 201 is specifically configured to:
acquiring and decompressing the PHP source code of the target version, for example, downloading and decompressing the PHP source code of the target version, for example, PHP7.3.16, decompressing the source code file by using a tar or decompression tool;
running/configuration (the source code contains configuration files for compiling configuration, environment checking and the like) in the decompressed source code catalog, and designating-enable-end= [ shared|static ] to enable an embedded module; it should be noted that, for-enable-end= [ shared|static ] the library type may be specified, where-enable-end represents the specification, shared represents the dynamics, static represents the static, and the implementation may be arbitrarily selected, in the embodiment of the present invention, a dynamic library is used as an example to describe, that is, specify-enable-end=shared to enable the embedded module, because the size of the executable file generated by using the dynamic library will be slightly smaller;
executing make and make install, generating libpp7. So, and installing (copying) to the dynamic library directory;
the PHP-embedded SAPI encapsulation module 202 is configured to encapsulate the PHP-embedded SAPI using the C language, and generate a C language code file for encapsulation call for a subsequent Golang call.
The PHP embedded SAPI packaging module 202 is specifically configured to:
newly built php_end_exec.c and php_end_exec.h files (the code file name of C encapsulation PHP SAPI) for encapsulating the C file and the corresponding header file of PHP embedded SAPI;
introducing a #include 'SAPI/emubed/php_emubed.h' into the php_emud_exec.h file, wherein SAPI/emubed/php_emubed.h defines the declaration of PHP emubed SAPI for an external interface;
encapsulation of PHP embedded SAPI is implemented in php_encapsulated_exec: performing initialization operation of the PHP framework, calling a method php_execution_script of the SAPI execution script to realize embedding and executing the PHP script, and completing ending work such as closing recovery resources of the PHP framework after executing the php_execution_script method; the embedded execution method entry of the PHP script is defined as execution_php.
The Golang package construction module 203 is configured to construct a Golang package, enable cgo, and further encapsulate an embedded execution entry of a single PHP script encapsulated in C language: exec (filename, argc, argv).
The Golang packet construction module 203 is specifically configured to:
newly creating a Golang package named PHP, and newly creating a PHP folder, and newly creating an emmbedExec. Go under the PHP directory to be used for storing codes of PHP script execution entries of Golang further encapsulation C encapsulation (namely php_emmbed_exec. C and php_emmbed_exec. H of step S2); that is, the invention performs secondary encapsulation on the encapsulated C language code file through the emmbedExec.go, and the method interface in the Golang package can be directly called in the subsequent Golang service code;
golang's cgo is enabled in emmbedExec.go to invoke the C code in PHP Ebed SAPI encapsulation module 202. In a specific embodiment of the present invention, import "C" enables cgo in EMbedExec. Go to invoke the encapsulated C language code files in PHP Ebed SAPI encapsulation module 202.
And adding # cgo related compiling FLAGS into the emmbedExec. Go, and introducing a c-header file php_emmbed_exec.
Invoking script execution capability of PHP-EmbeddsPI encapsulation in C language in PHP-EmbeddsPI encapsulation module 202, implementing an entry for embedded execution of a single PHP script in emmbedExec. Go: exec (filename, argc, argv).
And the single embedded execution entry calling module 204 is used for packaging batch execution entries, traversing the scripts imported by the joining, calling the single embedded execution entry in Goroute and executing concurrently, thereby finally realizing the support of the execution of single and multiple scripts. The entry of the single script execution is implemented in step S3: exec (filename, argc, argv), the entry method of the step of executing a plurality of scripts is implemented based on the entry of the single script execution, namely, multi Exec ([ (] files). .
The single embedded execution portal invocation module 204 is specifically configured to:
adding a batch execution inlet MultiExec ([ ] files) into the emmbedExec.go, wherein the entering is slicing of each structure body, and receiving execution scripts with variable length;
traversing the incoming files, embedding and executing each file in Goroute, and calling an executing single script method encapsulated in the Golang package construction module 203: go func () { Exec (filename, argc, argv) }.
The service code invoking and executing module 205 is configured to invoke, according to implementation requirements, a Golang package (named PHP, and the main implementation code file is emmbedexec. Go) encapsulated by the Golang package constructing module 203 in a Golang service code, and concurrently execute the incoming PHP script.
The service code call execution module 205 is specifically configured to:
golang package generated by Golang package construction module 203 is imported into the service logic code: import "php".
The PHP library is called or a single script is executed, and related optional parameters are transmitted;
calling php.MultiExec where multiple PHP scripts need to be executed concurrently;
and compiling to generate an executable file and running, and embedding and executing PHP scripts according to business logic.
Examples
As shown in fig. 3, in this embodiment, the implementation method of embedding PHP script in Golang and concurrently executing in golutine includes the following steps:
step S1, when compiling PHP, passing instructions: configuration-enable; compiling is completed to generate libpph.so (dynamic library) or. La/. Lib (static library) required by PHP embedded SAPI call;
specifically, step S1 further includes:
step S100, downloading and decompressing PHP source codes of target versions, for example PHP7.3.16, decompressing source code files by using tar or a decompression tool;
step S101, entering a decompressed source code catalog, running/configuration, and designating-enable-end=shared to enable an embedded module, wherein shared compiling dynamic Library is taken as an example, and enabling embedded to compile PHP into Library for other programs to call;
step S102, executing make to generate libppp 7.So, executing make install (copy) to the system dynamic library directory;
s2, writing a C language code, and packaging PHP embedded SAPI;
specifically, step S2 further includes:
step S200, newly creating a php_end_exec.c and a php_end_exec.h file;
step S202, introducing a # include 'SAPI/emud/php_emud.h' into a php_emud_exec.h file, wherein the SAPI/emud/php_emud.h defines the declaration of PHP emud SAPI for an external interface;
step S203, the PHP-embedded SAPI is encapsulated in php_encapsulated_exec.c, and the PHP executing method is embedded: execution_php; the code in this embodiment is as follows:
void execute_php(char *filename, int argc, char * argv[]) {
PHP_EMBED_START_BLOCK(argc,argv);
// Attempt to execute script file.
zend_file_handle script;
...
ret = php_execute_script(&script);
PHP_EMBED_END_BLOCK();
...
step S3, writing a Golang package, enabling cgo, and further packaging an embedded execution entry of a single PHP script packaged by a C language: exec (filename, argc, argv);
specifically, step S3 further includes:
step S300, newly creating a php folder, and newly creating an emmbedExec. Go under the php directory, wherein the Golang package name is changed into php;
step S301, import "C" enable cgo in the emmbedExec. Go to call the encapsulated C language code file in step S2; for example:
package php
import "C"
step S302, adding # cgo related compiling FLAGS, introducing a c-header file php_emmbed_exec.h and the like;
// #cgo CFLAGS: -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM
// #cgo CFLAGS: -I/usr/include/php/Zend -Iinclude
//
// #include <stdlib.h>
// #include <main/php.h>
// #include "php_embed_exec.h"
step S303, calling script execution capability of PHP embedded SAPI encapsulation in the C language in step S2, and setting an entry for embedding and executing a single PHP script in the emmbedExec. Exec (filename, argc, argv).
func Exec(filename string, argc int, argv interface{}) error {
v, err := NewValue(argv)
f := C.CString(filename)
defer C.free(unsafe.Pointer(f))
...
_, err := C.execute_php(f, agrc, v)
...
S4, packaging batch execution inlets, traversing the scripts input by the input, calling a single embedded execution inlet in Goroutine, and executing concurrently;
specifically, step S4 further includes:
step S400, continuously adding a batch execution entry MultiExec ([ ] Files) at the emmbedExec. Go, taking a slice of a structure as a reference, and receiving execution scripts with variable length;
type Files struct {
filename string
argc int
argv interface{}
}
step S401, traversing the incoming files, embedding and executing each file in Goroute, and calling the single script executing method packaged in step S3: go func () { Exec (filename, argc, argv) });
func MultiExec(scripts []Files) error {
for _,script range scripts {
go func(script Files) {
...
Exec(script.filename, script.argc, scripts.argv)
...
}(script)
}
...
}
step S5, calling a step S3 to package a Golang package (named PHP, a main implementation code file is EMbedExec. Go) according to the implementation requirement in the Golang service code, and concurrently executing an incoming PHP script (optional parameters);
specifically, step S5 further includes:
in step S500, golang package generated in step S3, i.e. import "php", is imported into the service logic code.
Step S501, php.Exec is called at the place where the PHP library is required to be called or a single script is executed, and relevant optional parameters are transmitted in;
step S502, calling php.MultiExec at a place where a plurality of PHP scripts are required to be executed concurrently;
step S503, compiling and generating an executable file and running, and embedding and executing PHP scripts according to business logic.
The above embodiments are merely illustrative of the principles of the present invention and its effectiveness, and are not intended to limit the invention. Modifications and variations may be made to the above-described embodiments by those skilled in the art without departing from the spirit and scope of the invention. Accordingly, the scope of the invention is to be indicated by the appended claims.
Claims (10)
1. A method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script comprises the following steps:
step S1, when compiling PHP, enabling an embedded module to generate a dynamic library or a static library required by PHP embedded SAPI call;
s2, packaging the PHP embedded SAPI by using a C language to generate a C language code file for packaging and calling;
s3, constructing a Golang package, starting cgo, and further packaging an embedded execution entry of a single PHP script packaged by a C language;
s4, packaging batch execution inlets, traversing the scripts input by the input, calling a single embedded execution inlet in Goroutine, and executing concurrently;
and S5, calling the Golang package packaged in the step S3 in the Golang service code according to the implementation requirement, and executing the incoming PHP script concurrently.
2. The method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to claim 1, wherein step S1 further comprises:
step S100, acquiring and decompressing PHP source codes of a target version;
step S101, entering into a decompressed source code catalog, and operating/configuration to enable Embedded;
step S102, executing make and make install, generating a dynamic library, and installing the dynamic library into a dynamic library catalog.
3. The method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to claim 2, wherein step S2 further comprises:
step S200, newly creating php_end_exec.c and php_end_exec.h files for packaging the C file and the corresponding header file of the PHP embedded SAPI;
step S201, introducing # include 'sapi/emuded/php_emuded.h' into the php_emud_exec.h header file;
step S202, packaging PHP embedded SAPI by using php_end_exec.c, implementing a method for embedding and executing PHP script, and determining an embedded and executed entry execution_php of the PHP script.
4. The method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to claim 3, wherein the method comprises the following steps: in step S202, an initialization operation of the PHP framework is performed, the php_execution_script of the SAPI execution script is invoked to implement embedded execution of the PHP script, and the closing recovery resource ending operation of the PHP framework is completed after the php_execution_script method is executed.
5. The method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to claim 4, wherein step S3 further comprises:
step S300, newly creating a Golang package named php, creating a php folder, and newly creating an emmbedExec. Go under the php directory;
step S301, enabling Golang cgo in the emmbedExec. Go to call the C language code file packaged in step S2;
step S302, adding # cgo related compiling FLAGS into the emmbedExec. Go, and introducing a c-header file php_emmbed_exec.h;
step S303, calling the script execution capability of the PHP embedded SAPI package in the C language in the step S2, and realizing the embedded execution of the entry of the single PHP script in the EMbedExec.
6. The method for improving the execution efficiency based on Golang protocol Cheng Qianru PHP script according to claim 5, wherein the method comprises the following steps: in step S301, import "C" enable cgo in emmbedexec.
7. The method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script of claim 6, wherein step S4 further comprises:
step S400, adding a batch execution inlet MultiExec ([ ] files) into the emmbedExec. Go, taking into account each structural body slice, and receiving execution scripts with variable length;
step S401, traversing the incoming files, embedding and executing each file in Goroute, and calling the single script executing method packaged in step S3.
8. The method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script of claim 7, wherein step S5 further comprises:
step S500, importing the Golang packet generated in the step S3 into a service logic code;
step S501, php.Exec is called at the place where the PHP library is required to be called or a single script is executed, and relevant optional parameters are transmitted in;
step S502, calling php.MultiExec at a place where a plurality of PHP scripts are required to be executed concurrently;
step S503, compiling and generating an executable file and running, and embedding and executing PHP scripts according to business logic.
9. The method for improving execution efficiency based on Golang protocol Cheng Qianru PHP script according to claim 1, wherein the method comprises the following steps: and a Zend virtual machine is embedded in the Golang program, so that interaction with the PHP program is realized.
10. An apparatus for improving execution efficiency based on Golang protocol Cheng Qianru PHP script, comprising:
the PHP script compiling module is used for starting the embedded module when compiling the PHP script and generating a dynamic library or a static library required by PHP embedded SAPI call;
the PHP embedded SAPI packaging module is used for packaging the PHP embedded SAPI by using a C language to generate a C language code file for packaging and calling;
the Golang package construction module is used for constructing a Golang package, starting cgo and further packaging an embedded execution entry of a single PHP script packaged by a C language;
the single embedded execution entry calling module is used for packaging batch execution entries, traversing the scripts input by the input, calling the single embedded execution entry in Goroute and executing concurrently;
and the service code calling execution module is used for calling the Golang package packaged by the Golang package construction module in the Golang service code according to the implementation requirement and concurrently executing the incoming PHP script.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310294655.3A CN116136787A (en) | 2023-03-23 | 2023-03-23 | Method and device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310294655.3A CN116136787A (en) | 2023-03-23 | 2023-03-23 | Method and device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN116136787A true CN116136787A (en) | 2023-05-19 |
Family
ID=86334421
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310294655.3A Pending CN116136787A (en) | 2023-03-23 | 2023-03-23 | Method and device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN116136787A (en) |
-
2023
- 2023-03-23 CN CN202310294655.3A patent/CN116136787A/en active Pending
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US20200151384A1 (en) | System and method for provisioning a mobile software application to a mobile device | |
| CN103069385B (en) | Systems and methods for dynamically loading graph-based computing | |
| US7047530B2 (en) | Method and system for cross platform, parallel processing | |
| WO2022166480A1 (en) | Task scheduling method, apparatus and system | |
| Cox et al. | The Go programming language and environment | |
| CN111506368B (en) | Method, device, equipment and storage medium for converting asynchronous call into synchronous call | |
| WO2006009287A1 (en) | Automatic converting program and program conversion server | |
| US7555746B2 (en) | System and method for registering native libraries with non-native enterprise program code | |
| CN112650502A (en) | Batch processing task processing method and device, computer equipment and storage medium | |
| US20130139185A1 (en) | Intercepting and tracing interface routine transactions | |
| CN120010835A (en) | Application development method, device, electronic device and storage medium | |
| US11435989B2 (en) | Thread-local return structure for asynchronous state machine | |
| CN114327479A (en) | Data processing method and data processing device for big data | |
| CN116136787A (en) | Method and device for improving execution efficiency based on Golang protocol Cheng Qianru PHP script | |
| CN108647087B (en) | Method, device, server and storage medium for realizing reentry of PHP kernel | |
| Takaso et al. | Component Framework for Multiprocessor Real-Time Operating Systems | |
| CN115718588A (en) | Method, device, storage medium and processor for publishing network service | |
| JP2023046244A (en) | Deployment of Portable Radio Access Network Containerized Network Functions (RAN CNF) Across Multiple RAN Hardware Platforms | |
| US20090019159A1 (en) | Transparently externalizing plug-in computation to cluster | |
| CN117111904B (en) | Method and system for automatically converting Web applications into serverless functions | |
| Gál | JavaScript-only Parallel Programming of Embedded Systems | |
| Mehrabi et al. | @ PT: Unobtrusive parallel programming with Java annotations | |
| Möller et al. | Cppless: Productive and performant serverless programming in c++ | |
| Troelsen et al. | Multithreaded, Parallel, and Async Programming | |
| Fan et al. | Balancing parallelization and asynchronization in event‐driven programs with OpenMP |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |