Hướng dẫn php get pid - php get pid

[Php 4, Php 5, Php 7, Php 8]

GetMypid - Nhận ID quy trình của PHPGets PHP's process ID

Sự mô tả

getMypid []: int | false[]: int|false

Thông số

Chức năng này không có tham số.

Trả về giá trị

Trả về ID quy trình PHP hiện tại hoặc false khi lỗi.false on error.

Ghi chú

Cảnh báo

ID quy trình không phải là duy nhất, do đó chúng là một nguồn entropy yếu. Chúng tôi khuyên bạn nên chống dựa vào PID trong bối cảnh phụ thuộc bảo mật.

Xem thêm

  • getMyGid [] - Nhận GID của chủ sở hữu Php
  • getMyuid [] - Nhận uid của chủ tập bản Php
  • GET_CURRENT_USER [] - Nhận tên của chủ sở hữu tập lệnh PHP hiện tại
  • getMyinode [] - Nhận được inode của tập lệnh hiện tại
  • getLastMod [] - có thời gian sửa đổi trang cuối cùng

Radu Cristescu ¶

9 năm trước

The lock-file mechanism in Kevin Trass's note is incorrect because it is subject to race conditions.

For locks you need an atomic way of verifying if a lock file exists and creating it if it doesn't exist. Between file_exists and file_put_contents, another process could be faster than us to write the lock.

The only filesystem operation that matches the above requirements that I know of is symlink[].

Thus, if you need a lock-file mechanism, here's the code. This won't work on a system without /proc [so there go Windows, BSD, OS X, and possibly others], but it can be adapted to work around that deficiency [say, by linking to your pid file like in my script, then operating through the symlink like in Kevin's solution].

#!/usr/bin/php

Bài Viết Liên Quan

Chủ Đề