简体   繁体   中英

A little php script (logical help needed)

I am a .net developer and devolving an application for a company. For that I need to write a little php script to meet my needs. 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. My idea is to use a simple text file instead of a mysql database (I am free to use a mysql db also). And then make two php pages. For example writer.php and reader.php

work of writer.php is very simple. 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. work done.

Now the logical questions.

  • reader.php will be read by 40 clients in the same time. If there is any conflicts?

  • If this method will be fast than mysql db?

  • If this method is more resource consuming than a mysql db?

You will have to lock the file for I/O for the time of writting ( PHP flock() function ). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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