search
HomeBackend DevelopmentPHP Tutorial(Personal open source) nginx source code comments

Address

https://github.com/langsim/nginx-1.6.2-comment

Introduction

I hope to complete a highly readable nginx source code comment.

Content that will not be commented

  1. spdy-related code, because spdy has been replaced by http2.
  2. Thread-related code, because at least in version 1.6.2 nginx threads are still in the experimental stage.
  3. Others than Linux Platform code.
  4. Code of other event models other than epoll
  5. Code of other compilers other than gcc.
  6. mail-related code.

Completion level

  1. core directory 60%
  2. event directory 20%
  3. http directory 10%
  4. os directory 80%

Function linked list

  1. http filter module, ngx_http_top_header_filter and ngx_http_top_body_filter will form two function linked lists, the calling order of the functions in the linked list will be the same as that of the corresponding module in the ngx_modules array The order is reversed.
  2. Many of the 11 stages of http request processing can have multiple callback functions. The order of calling callback functions in the same stage is the same as the order of the corresponding modules in the ngx_modules array.

Log

nginx has two log files by default:

  1. access.log: Each http request will generate a line of records in it.
  2. error.log: Some general, error or debug logs when nginx is running.

Process model

Four process states may appear after nginx is started:

  1. Single process running in the foreground
  2. Single process daemon mode
  3. One master process, one (or more) worker processes, one (or 0) ) cachemanager processes and one (or 0) cacheloader processes run together in the foreground
  4. A master process, one (or more) worker processes, one (or 0) cachemanager processes and one (or 0) cacheloader processes are in Run in daemon state.
    • The master process is used to start other processes during startup, and is used to manage other processes after startup is completed.
    • woker process, used to actually handle link requests.
    • The cachemanager process is used to clean cache files as required.
    • When the cacheloader process starts, it will index the cache files that meet the requirements in the cache directory in the memory, clear the cache files that do not meet the requirements, and then exit.
  5. After starting, send a signal to the main process of running nginx, and then exit.

Switching of process running status

  1. Reload configuration file (reload)
  2. Hot upgrade executable file

Compilation

nginx compilation is the same as the compilation method of regular open source software on the Linux platform, both are run./ configure && make && make install, you can add your own custom options after ./configure.

nginx uses signals

  1. TERM, INT for quick shutdown
  2. QUIT for graceful shutdown
  3. HUP for smooth restart and reloading the configuration file
  4. USR1 to reopen the log file, which is more useful when cutting logs
  5. USR2 for smooth upgrade executable The program
  6. WINCH shuts down the working process gracefully

nginx memory pool

nginx has two memory pools

  1. The memory pool used to allocate memory on shared memory
  2. The memory pool used to apply for memory on ordinary memory, the purpose is Efficient use of memory

nginx uses calculation hash algorithm

  1. crc32
  2. crc16
  3. sha1
  4. murmurhash
  5. md5

nignx process communication and synchronization

  1. shared memory Use
  2. signal
  3. unix socket
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the (personal open source) nginx source code comments, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.