Experience --composer use of project development

Foreword

Maintenance of the master project is the main project for the development of php language, in recent years introduced the concept Composer expansion pack, combined with the actual situation of the past few years the use of experience to talk about it.


Composer of nature

The polymerization process is a personal feeling Composer project code file Solved by the line, it does not belong to the line. Tag including play, through a variety of detection, the rsync comparison, Jenkins construct, or an internal cloud selected host, etc. or without the use of docker, are in fact the process line.

I understand the contents of the line, the request should be provided directly support the corresponding content. When a request came, through a gateway, local arrival execution of the script code logic is executed, and then returns the process should be. Check the site -> decode -> execution, which is the essence of program execution.


Composer advantage

Composer PHP is a dependency management tool, it has a mature community and related use of personnel, developers use some ready-made package will undoubtedly increase the efficiency of development.


Compare expansion pack

Language is different from the line item and java php projects php is intact understand that the code lines are operated to push, the java compiled form is generated after the line tundish. For example: if the project contains 10 php file, when it should be on the line 10 files, java program is to generate an on-line on-line package jar after compilation. The sum of the project document php If you compare the impact of the General Assembly, but does not require pre-compiled php on line, which is extremely convenient.


php C expansion pack, although it is associated with php, but the entire installation process is the same as with the above process of java, downloaded from a source project, compiled to generate a .so file, this .so file should only contain information related to functions provided function, and all the non-provision of services related to online content (ReadMe, unit test), should all be filtered out.


php extension package, and it should be the same php code, the compiler does not need the extra line. That is basically how many file extensions included in the package, how many files at the line. Of course, can be optimized only part you need on-line, filtering irrelevant sections within Diaobao (test code, all kinds of documentation, content, etc.), currently used on-line, basically did not include this filter, this can be optimized, but It will also bring some new problems, which files need to distinguish between on-line, which does not require filtering criteria on the line.


We previously used three kinds of development methods below:

image.png

Note: The above refers to merge code on line are completed, by business line under test, prepared by then create tag line on the script trigger mode.


Comparative characteristics of these three ways:

1. Without composer package, this situation is not a member of our code composer relevant content, on-line process is to create a tag, time to publish online, of course, now commonly used method is to publish than rsync file, on-line time t = create tag + rsync code time.


2. composer install locally, this is a way that I use in a project, maintainable code library contains third-party expansion packs, submitted the code contained in third-party libraries introduced. I included Expansion packs + business code when creating the tag. Because composer install the next line, so the line time t = create tab + rsync code time.


3. The first pack and then composer install, due to a previous system architecture philosophy, we will go to perform the mapping process compoer install something like. Create execution tag, the tag service code at this time is minimal, but the line code should still composer install, increased Expansion packs + business code, this time on the time line t = create tab + composer install + rsync code.


If your project using Composer's expansion pack, on-line time t, the length of the case of small your business impact cases, you can choose the third, if there is need for speed on the line, then, is to consider the time of intermediate steps.


Choose whether to use the extended package composer introduced into the actual situation

Universal expansion packs generally only consider the needs of the public, are more full-function, will be compatible to a variety of circumstances, this will increase the cost of expansion packs and learning mentioned, it is possible most of what you want, there may be a part of It is what you want. Introduce a case, and I before the migration project on a call gitlab api application logic, I found a previous developer with a classmate expansion pack, compared to the use of third-party extensions and packages directly invoke the migration costs gitlab api interface, before migrating find yourself familiar with this interface expansion pack will increase the cost of learning to read the help of gitlab found gitlab api call interface simple enough and in detail, the final choice of direct call interface, faster migration is complete.


If you are using while rsync side of the on-line mode, the file on the line overall code contains the number will affect the time difference of each file on a line of code, if the time difference is too large, it will cause the code lines are running because they can not class, It reported a large number of transient 502, (not yet fully positioned, with the inference is related to, and perhaps some of the wording is loaded php related follow-up in late.)


Rollback and expansion

Rollback and expansion project for a highly concurrent operation of the line are two common operations. From the two decided to do this operation, the deployment environment, the code is a fast push to complete the corresponding process. The size of the content and length of the line of code deployment time that we need to consider. Requirements: fast and efficient. Our roll back time or a trigger to build the history of the tag, and then perform composer install, and finally rsync code than to process on-line. Currently the composer install when using a local cache, the cache related packages installed, the fastest takes about 10s it, if this layer is not cached, and that this time may need more.


Expansion Pack Quality

Third-party expansion pack is not entirely without problems, this may be the difference between open source software and commercial software maintenance own right, as shown in this Symfony warnings related to the user a reasonable assessment of the impact of this problem on your line of code.

image.png


Finally, according to the actual situation of the project reasonable use composer.


Guess you like

Origin blog.51cto.com/9681602/2435658