Php reads the content in TXT in order of the number of rows. solution:

Source: Internet
Author: User
Php reads the content in the TXT file in order of the number of rows. each line in the txt file stores an IP address, which is now requested by different computers. each request is read in order of the number of rows. how can this problem be written? ------ Solution -------------------- what is a request from a different computer? ------ Solution ---------------------- reference: Reference: according to the meaning of the landlord: PHP & nbsp; code $ conts & php read the contents of the TXT in order of the number of lines
Each line in the txt file stores an IP address.
Currently, different computer requests are used to read data in the order of the number of rows.
How to write this?

------ Solution ----------------------
What is a request from a different computer?
------ Solution ----------------------
Reference:
Reference:

According to the meaning of the landlord:
PHP code

$ Conts = file_get_contents ($ filename );
$ ArrConts = explode ("\ n", $ conts );
Foreach ($ arrConts as $ cont ){
$ Pos = strpos ($ cont, $ _ SERVER ['remote _ ADDR ']);
If ($ pos = ......

$ Filename = "/root/a.txt ";

But there is a difference with #4. wait for other experts to eat first!
------ Solution ----------------------
Reference:
Reference:

What is a request from a different computer?


It is possible that three or more computers need to read the contents in the txt file at the same time, and the ip addresses read by different computers are the same.


Are the ip addresses read by different computers the same? So you want computer a to read 1 Computer B to read 2 computer c to read 3?
Go to the database.


------ Solution ----------------------

$num = 0;
if(file_exists('count.txt')) $num = file_get_contents('count.txt');
$ar = file('ip.txt');
echo $ar[$num++];
file_put_contents('count.txt', $num, LOCK_EX);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.