简体   繁体   English

一点php脚本(需要逻辑帮助)

[英]A little php script (logical help needed)

I am a .net developer and devolving an application for a company. 我是.net开发人员,正在为一家公司转让应用程序。 For that I need to write a little php script to meet my needs. 为此,我需要编写一些PHP脚本来满足我的需求。 My app need to check some information which randomly change almost every second from internet. 我的应用程序需要检查一些信息,这些信息几乎每秒钟都会从互联网上随机更改。 I am thinking to make a php script so that I can give app the needed information. 我正在考虑制作一个php脚本,以便我可以为应用提供所需的信息。 My idea is to use a simple text file instead of a mysql database (I am free to use a mysql db also). 我的想法是使用简单的文本文件而不是mysql数据库(我也可以自由使用mysql db)。 And then make two php pages. 然后制作两个php页面。 For example writer.php and reader.php 例如writer.php和reader.php

work of writer.php is very simple. writer.php的工作非常简单。 This file will save the submitted data to the text file I want to use as db. 该文件会将提交的数据保存到我想用作数据库的文本文件中。

reader.php will read the text file and then show as simple text and on every read it will also empty the text file.This file will be read by my app. reader.php将读取文本文件,然后显示为简单文本,并且每次读取时还将清空文本文件。此文件将由我的应用读取。 work done. 完成工作。

Now the logical questions. 现在是逻辑问题。

  • reader.php will be read by 40 clients in the same time. 40个客户端将同时读取reader.php。 If there is any conflicts? 是否有冲突?

  • If this method will be fast than mysql db? 如果这种方法会比mysql db快?

  • If this method is more resource consuming than a mysql db? 如果此方法比mysql db消耗更多资源?

You will have to lock the file for I/O for the time of writting ( PHP flock() function ). 编写时,您将必须为I / O锁定文件( PHP flock()函数 )。 This may slow down things a bit when there will be more clients at same time, as when file will be locked by one user, everyone else would have to wait. 当同时有更多的客户端时,这可能会放慢速度,因为当一个用户锁定文件时,其他所有人将不得不等待。 The other problem that may appear when writting alot o data is that writting queue may become infinite when there would be many write requests. 写入大量数据时可能出现的另一个问题是,当有许多写入请求时,写入队列可能会变得无限大。

MySQL seems to be better idea, as it caches both write and read requests, and it is implemented to avoid simultanous access conflicts. MySQL似乎是一个更好的主意,因为它可以缓存写入和读取请求,并且可以避免同时发生访问冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM