Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference in efficiency between reading and writing files and reading and writing databases in php

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "what is the difference between the efficiency of reading and writing files and reading and writing database in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

This question comes to mind only recently, that is, whether it is faster to read the file or the database, how much faster, Tianyuan has also searched, no netizens have answered this question, or it may be too simple. In this paper, we will measure it. Due to time constraints, VC has not yet been installed, Tianyuan has first tested it with PHP, and next time we have time to add a test to this article. Because the underlying parsing of PHP should also be based on C, it is estimated that the environmental test results of the two are similar, with big gains from minor problems, so let's take a look at the test process and results.

The test procedure is as follows:

Note 1: because the read database statement calls the simple packet function twice, the read file is also changed to call twice in a row, the database record ID is 1 in the first item, and the unique index.

Note 2: test twice, one is 4K data, the other is plastic data.

The copy code is as follows:

Set_time_limit (0)

Function fnGet ($filename)

{

$content = file_get_contents ($filename)

Return $content

}

Function fnGetContent ($filename)

{

$content = fnGet ($filename)

Return $content

}

$times=100000

Echo 'database query results:'

/ /--

$begin=fnGetMicroTime ()

For ($iS0 / SELECT log_Content FROM blog WHERE log_ID='1' _ blank _ query ("iTunes")

$row=$dbcon- > mydb_fetch_row ($res)

$content=$row [0]

}

Echo 'fetch_row'. $times.' Time:'. (fnGetMicroTime ()-$begin). Seconds'

/ /--

$begin=fnGetMicroTime ()

For ($iS0 / SELECT log_Content FROM blog WHERE log_ID='1' _ blank _ query ("iTunes")

$row=$dbcon- > mydb_fetch_array ($res)

$content=$row ['log_Content']

}

Echo 'fetch_array'. $times.' Time:'. (fnGetMicroTime ()-$begin). Seconds'

/ /--

$begin=fnGetMicroTime ()

For ($iS0 / SELECT log_Content FROM blog WHERE log_ID='1' _ blank _ query ("iTunes")

$row=$dbcon- > mydb_fetch_object ($res)

$content=$row- > log_Content

}

Echo 'fetch_object'. $times.' Time:'. (fnGetMicroTime ()-$begin). Seconds'

/ /--

$dbcon- > mydb_free_results ()

$dbcon- > mydb_disconnect ()

FnWriteCache ('test.txt',$content)

Echo 'directly read file test results:'

/ /--

$begin=fnGetMicroTime ()

For ($iSuppli

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report