web伺服器如何偵聽新請求?

在瞭解web伺服器及其工作方式時,您可能會好奇,他們是在不斷地偵聽請求,還是等到收到請求後才採取行動。有鑑於此,今天的超級使用者問答帖子有了滿足讀者好奇心的答案。...

web伺服器如何偵聽新請求?

在瞭解web伺服器及其工作方式時,您可能會好奇,他們是在不斷地偵聽請求,還是等到收到請求後才採取行動。有鑑於此,今天的超級使用者問答帖子有了滿足讀者好奇心的答案。

今天的問答環節是由SuperUser提供的,SuperUser是Stack Exchange的一個分支,是一個由社群驅動的問答網站分組。

截圖由xmodulo/Linux截圖(Flickr)提供。

問題

超級使用者讀者user2202911想知道web伺服器如何偵聽新請求:

I am trying to understand the ‘deeper level’ details of how web servers work. I want to know if a server, say Apache, for instance, is continuously polling for new requests or if it works by some sort of interrupt system. If it is an interrupt, what is sparking the interrupt? Is it the network card driver?

web伺服器如何偵聽新請求?

答案

超級使用者貢獻者Greg Bowser為我們提供了答案:

The short answer is some sort of interrupt system. Essentially, they use blocking I/O, meaning they sleep (block) while waiting for new data.

  1. The server creates a listening socket and then blocks while waiting for new connecti***. During this time, the kernel puts the process into an interruptible sleep state and runs other processes. This is an important point; having the process poll continuously would waste CPU resources. The kernel is able to use the system resources more efficiently by blocking the process until there is work for it to do.
  2. When new data arrives on the network, the network card issues an interrupt.
  3. Seeing that there is an interrupt from the network card, the kernel, via the network card driver, reads the new data from the network card and stores it in memory. (This must be done quickly and is generally handled inside the interrupt handler.)
  4. The kernel processes the newly arrived data and associates it with a socket. A process that is blocking on that socket will be marked runnable, meaning that it is now eligible to run. It does not necessarily run immediately (the kernel may decide to run other processes still).
  5. At its leisure, the kernel will wake up the blocked web server process. (Since it is now runnable.)
  6. The web server process continues executing as if no time has passed. Its blocking system call returns and it processes any new data. Then go to step 1.

有什麼要補充的解釋嗎?在評論中發出聲音。想從其他精通技術的Stack Exchange使用者那裡瞭解更多答案嗎?在這裡檢視完整的討論主題。

  • 發表於 2021-04-11 04:35
  • 閱讀 ( 33 )
  • 分類:網際網路

你可能感興趣的文章

關於javarmi註冊中心以及如何使用它的所有內容

...個API(應用程式程式設計介面),用於從一個程式(稱為伺服器)匯出一個物件,並從另一個程式(稱為客戶機)呼叫該物件的方法,可能執行在不同的計算機上。 ...

  • 發佈於 2021-03-12 15:58
  • 閲讀 ( 64 )

不,linux不需要防病毒或防火牆

... 你唯一需要防火牆的時候,就是在你的系統上執行某種伺服器應用程式的時候。這可能是web伺服器、電子郵件伺服器、遊戲伺服器等。在這種情況下,防火牆將限制某些埠的傳入連線,確保它們只能與適當的伺服器應用程式進...

  • 發佈於 2021-03-12 20:15
  • 閲讀 ( 52 )

什麼是cgi指令碼,它們如何改進網站?

CGI代表公共閘道器介面。它是web伺服器執行程式併為web瀏覽器生成輸出的標準協議。該程式被稱為CGI程式(或CGI指令碼)。當用戶的web瀏覽器請求特定的URL時,它代表web伺服器執行以產生輸出。 ...

  • 發佈於 2021-03-13 08:17
  • 閲讀 ( 43 )

什麼是刮網?如何從網站收集資料

...的關係不大,但越來越多的裝置將這些資訊從世界各地的伺服器傳送到我們的眼睛和大腦。 ...

  • 發佈於 2021-03-22 00:36
  • 閲讀 ( 46 )

為什麼wi-fi direct沒有你想象的那麼安全

... 然後,連線的裝置可以完全訪問遠端控制功能以及web伺服器,並可以對媒體伺服器和所有連線的裝置進行讀/寫訪問。所有這些許可權都是在沒有身份驗證或通知的情況下授予的。或許不出意外,WD電視直播在2016年停播。 ...

  • 發佈於 2021-03-25 20:57
  • 閲讀 ( 42 )

什麼是csrf攻擊?如何防止它們?

...洞的最古老方法之一。它針對通常需要登入等身份驗證的伺服器端web交換機。在CSRF攻擊過程中,攻擊者的目標是強迫其受害者代表他們發出未經授權的惡意web請求。 ...

  • 發佈於 2021-03-29 05:49
  • 閲讀 ( 48 )

什麼是127.0.1、localhost或環回地址?

...線到您當前使用的計算機。當您想連線到自己計算機上的伺服器時,這很方便。 ...

  • 發佈於 2021-03-30 20:02
  • 閲讀 ( 50 )

如何在ubuntu上設定遠端桌面

...我們會教你怎麼做。 ubuntu內建的“螢幕共享”是一個vnc伺服器 當您與遠端ubuntulinux計算機建立SSH連線時,您會得到一個終端視窗介面。這對於許多工來說都是非常好的,比如系統管理,它的優點是輕量級連線。沒有圖形可以從...

  • 發佈於 2021-04-03 07:59
  • 閲讀 ( 63 )

什麼是反向ssh隧道?(以及如何使用)

...用隧道。 所以我們得到了“反向SSH隧道”這個名字 它是如何工作的? 反向SSH隧道依賴於遠端計算機使用已建立的連線來偵聽來自本地計算機的新連線請求。 遠端計算機監聽本地計算機上的網路埠。如果它檢測到對該埠的SSH請...

  • 發佈於 2021-04-03 08:32
  • 閲讀 ( 49 )

htg解釋:什麼是埠掃描?

...您連線到一個安全的網站時,您的web瀏覽器正在與監聽該伺服器埠443的web伺服器進行通訊。 服務並不總是必須在這些特定埠上執行。例如,如果願意,可以在埠32342上執行HTTPS web伺服器,或者在埠65001上執行安全Shell伺服器。這...

  • 發佈於 2021-04-04 08:28
  • 閲讀 ( 65 )
aypt3486
aypt3486

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦