ホームページ  >  記事  >  バックエンド開発  >  Nginx のメイン ngx_init_cycle() の予備調査 (パート 1)

Nginx のメイン ngx_init_cycle() の予備調査 (パート 1)

WBOY
WBOYオリジナル
2016-08-08 09:28:471213ブラウズ

ngx_init_cycle() に関する Nginx の主な予備調査 (パート 1)

ngx_init_cycle() 関数は非常に大きいため、ここでは最初の 400 行以上の関数呼び出し関係のみを示し、最後の 400 行以上は後の記事。

-->ngx_init_cycle(&init_cycle)
	    -->ngx_timezone_update()
		    -->time()
			-->localtime()注1:
		-->ngx_timeofday()
		-->ngx_time_update()
		    -->ngx_gettimeofday() -- gettimeofday()
			-->ngx_gmtime()
			-->ngx_localtime()
			-->ngx_memory_barrier()
		-->ngx_increase_pipe_generation()
		-->ngx_create_pool()
			-->ngx_memalign() --  ngx_alloc(size, log)
		-->ngx_pcalloc()
		    -->ngx_palloc()
			    -->ngx_align_ptr()注2:
			    -->ngx_palloc_block()
			        -->ngx_memalign()
				    -->ngx_align_ptr()
			    -->ngx_palloc_large()
			        -->ngx_alloc()
				        -->malloc()
				    -->ngx_palloc()	
			-->ngx_memzero()
			    -->memset()
		-->ngx_list_init()
		    -->ngx_palloc()
		-->ngx_queue_init()
		-->ngx_strlen() -- strlen()
		-->ngx_pnalloc()
		    -->ngx_palloc_block()
			-->ngx_palloc_large()
		-->ngx_strlow()
		    -->ngx_tolower() -- ((c >= 'A' && c <= &#39;Z&#39;) ? (c | 0x20) : c)
		-->ngx_array_create()
		    -->ngx_palloc()
			-->ngx_array_init()
			    -->ngx_palloc()
		-->ngx_conf_param()
		    -->ngx_memzero()
			-->ngx_conf_parse()
		-->ngx_conf_parse()
		    -->ngx_open_file()  -- open()
			-->ngx_fd_info()  -- fstat()
			-->ngx_alloc()
			-->ngx_conf_read_token()
			    -->ngx_file_size()
				-->ngx_memmove()  --  memmove()
				-->ngx_read_file()   -- read()
				-->ngx_write_console() -- ngx_write_fd()
				    --> write()
				-->ngx_array_push()
			-->ngx_conf_handler()
		-->ngx_show_dso_directives()
		    -->ngx_get_conf()
		-->ngx_is_dynamic_module()
		    -->ngx_get_conf()
		-->ngx_test_lockfile()
		    -->ngx_open_file()
			-->ngx_close_file()
			-->ngx_delete_file()
		-->ngx_create_paths()
		    -->ngx_create_dir() -- mkdir()
			-->ngx_file_info()
		-->ngx_log_open_default()
		    -->ngx_conf_open_file()

馴染みのない関数の使い方と知識ポイントを以下に示します。

注 1: time() 関数と localtime() 関数は Nginx 自体で実装されているわけではなく、ライブラリ関数です。使い方は以下の通りです

/**
	 * filename:    test_localtime.c
	 * description: used to see the usage of function localtime()
	 * date:        2015-03-06
	 * author:      HowardKing
	 * version:     1.0
	 */


	#include <stdio.h>
	#include <stdlib.h>
	#include <time.h>


	int main(void)
	{
			time_t timer; // time_t is long int
			struct tm *tblock;


			time(NULL);
			tblock = localtime(&timer);
			printf("Local time is: %s", asctime(tblock));


			return 0;
	}

プログラムの出力結果:
<span style="white-space:pre">	</span>Local time is: Fri Jul 31 05:00:00 4461676


注2: C言語のlong型は機械語長に相当しますが、 int型 一般的には4バイトと言われています。

/**
	 * filename:    test_unsigned_long.c
	 * description: find out the size of type long
	 * date:        20150306
	 * author:      HowardKing
	 * version:     v1.0
	 */


	#include <stdio.h>
	#include <stdlib.h>


	int main(void)
	{
			int ii = 100;
			unsigned long ll = 100;


			printf("%d\n", sizeof(ii));
			printf("%d\n", sizeof(ll));


			return 0;
	}

プログラム出力結果:
	4
	8

上記では、関連するコンテンツを含め、Nginx ngx_init_cycle() の主な説明 (パート 1) を紹介しています。PHP チュートリアルに興味のある友人に役立つことを願っています。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:Laravelの勉強メモ次の記事:Laravelの勉強メモ