Home Backend Development PHP Tutorial PHP generates millions of UIDs and stores them in files

PHP generates millions of UIDs and stores them in files

Aug 08, 2016 am 09:20 AM
time uid

This is a question asked in a group today. The main reason is that writing files takes a long time.

I am doing an experiment here. Every 20,000 UIDs are written into a file. One file is written approximately 280kb, so the overall writing time is only 13S

Post the code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

<code><span><span><?php</span>

set_time_limit(<span>0</span>);

 

<span>$starttime</span> = time();

 

<span>$fh</span> = fopen(<span>$filename</span>,<span>'w'</span>);

 

<span>for</span>(<span>$i</span>=<span>0</span>;<span>$i</span><<span>1000000</span>;<span>$i</span>++)

{

    <span>$uid</span> = uniqid();

    <span>if</span>(<span>$i</span>%<span>20000</span> == <span>0</span>)

    {

        <span>$filename</span> = <span>$i</span>.<span>'.txt'</span>;

 

    }

    fwrite(<span>$fh</span>,<span>$uid</span>.<span>' '</span>);

}

<span>$endtime</span> = time();

<span>echo</span><span>'总用时:'</span>.(<span>$endtime</span>-<span>$starttime</span>).<span>'s'</span>;

<span>?></span></span></code>

Copy after login

Copyright statement: This article is a blog This is an original article and may not be reproduced without the permission of the blogger.

The above introduces PHP to generate millions of UIDs and save them in files, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Where can I check the uid of Tomato Novel? Where can I check the uid of Tomato Novel? Feb 28, 2024 pm 04:25 PM

When using the Tomato Novel software, log in to your account so that you can enjoy more personalized services and convenience. After logging in to your account, you can also view your UID (Unique User Identifier), which is very important information. Sometimes this uid is very important, so where can you view your UID in Tomato Novels? Users who want to know, please follow this article to learn more about the viewing steps! Where to check the answer of Tomato Novel uid: [Tomato Novel] - [My] - [Feedback and Help] - [Feedback] - [Click 5 times]. Specific steps: 1. First open the Tomato Novel software. After entering the home page, we need to click [My] in the lower right corner; 2. Then in the My page, we slide to the page

Monotonic clock processing of time package Monotonic clock processing of time package Aug 04, 2023 pm 05:45 PM

Today we are mainly going to take a look at the time application method of golang time package. The general rule between the two is that "wall time" is used to tell time, and "monotonic clock" is used to measure time; there are other clock processing methods.

One-line command to find all real users in Linux One-line command to find all real users in Linux Feb 18, 2024 pm 05:50 PM

Hello everyone, I am Xianyu. Friends who have been exposed to Linux all know that there are three types of users in Linux (or Unix-like): Super user (UID 0): the root user, who has the highest permissions. System user (UID 1~999): System built-in user, used to run system services and daemon processes. Ordinary user (UID 1000~60000): Created to allow users to use Linux system resources. The account created by the user is generally an ordinary account. So now the question is, how to quickly find out the real users (root users and ordinary users) in Linux? Before we officially start, we first introduce a tool-getent. getent

Learn more about how to view Linux user UID and GID Learn more about how to view Linux user UID and GID Mar 20, 2024 pm 12:06 PM

User UID and GID are numerical identifiers used to identify users and groups in Linux systems. When using a Linux system, we often need to view the user's UID and GID in order to manage user and file permissions. This article will provide an in-depth introduction to the various ways to view user UID and GID in Linux systems, and attach specific code examples. 1. Check the user UID and GID through the command. Check the UID and GID of the current user: id. After running the above command, the system will display the UID, GID and GID of the current user.

How to use Java8 Time API How to use Java8 Time API Apr 28, 2023 pm 12:25 PM

1. Overview As part of this article, let us start with some problems with the existing Date and CalendarAPI and explore how the new Java8Date and TimeAPI solve these problems. We will also take a look at the core classes in the Java8 time class library, such as LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Period, Duration and their APIs. 2. The problem of thread safety of the old time API (before Java 8)-Date and Calendar classes are not thread-safe, making it difficult for developers to debug concurrency problems of these APIs and need to write additional code to deal with them.

What is the difference and usage between time and datetime in python What is the difference and usage between time and datetime in python May 02, 2023 am 11:01 AM

1. Two ways to represent time in Python: timestamp: offset in seconds relative to 1970.1.100:00:00, unique time tuple struct_time: a total of 9 elements>tm_year: year 1-12> tm_mon: month 1-12>tm_mday: day 1-31>tm_hour: hour 0-23>tm_min: minute 0-59>tm_sec: second 0-59>tm_wday: week 0-6 (0 means Sunday)>tm_day: Day of the year 1-366>tm_isdst: whether it is daylight saving, the default is -1.ti

How to obtain and convert time in Python time module How to obtain and convert time in Python time module May 13, 2023 pm 12:19 PM

Pythontime module time acquisition and conversion Python's Time library can perform time-related processing, such as accessing the current date and time, outputting time in different formats, and waiting for a specified time. 1. Get the time 1.1. Timestamp importtimetimestamp=time.time()#1682737552.5009851 Greenwich Mean Time (GMT) The total number of seconds from 00:00:00 on January 1, 1970 to the present 1.2. Structured time importtimestruct_time= time.localtime()#time.struct_time(tm_year=2

Linux Commands: Tips to View User UID and GID Linux Commands: Tips to View User UID and GID Mar 20, 2024 pm 12:33 PM

The Linux operating system is a widely used open source operating system that provides users with a wealth of command line tools to allow users to manage the system more easily. In a Linux system, each user has a unique user identifier (UserID, UID) and a group identifier (GroupID, GID). Understanding the user's UID and GID is very important for system management and file permission management. This article will introduce several techniques for viewing the user's UID and GID to better manage the Linux system.

See all articles