Hướng dẫn php get process list - danh sách quy trình php get

(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
<?php

define

('LOCK_FILE', "/var/run/" . basename($argv[0], ".php") . ".lock");

if (!

tryLock())
    die(
"Already running.\n");# remove the lock on exit (Control+C doesn't count as 'exit'?)
register_shutdown_function('unlink', LOCK_FILE);# The rest of your script goes here....
echo "Hello world!\n";
sleep(30);

exit(

0);

function

tryLock()
{
   
# If lock file exists, check if stale.  If exists and is not stale, return TRUE
    # Else, create lock file and return FALSE.
if (@symlink("/proc/" . getmypid(), LOCK_FILE) !== FALSE) # the @ in front of 'symlink' is to suppress the NOTICE you get if the LOCK_FILE exists
       
return true;# link already exists
    # check if it's stale
   
if (is_link(LOCK_FILE) && !is_dir(LOCK_FILE))
    {
       
unlink(LOCK_FILE);
       
# try to lock again
       
return tryLock();
    }

    return

false;
}
?>

Robert Mays Jr

11 năm trước

All of the examples above require you to have shell command execution turned on- this example uses only PHP functions and should work on any system (posix is included by default)-

the key is posix_getsid which will return FALSE if the processes does not exist.

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

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

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

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

Brooke tại Jump Dot Net

18 năm trước

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

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

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

Kevin Traas (Ktraas- at -gmail dot com) ¶

12 năm trước

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

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

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

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.0

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.1

Martijn tại Nowhere dot com ¶

6 năm trước

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.2

Brospam tại Gmail Dot Com ¶

9 năm trước

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.3

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.4

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

Robert Mays Jr

12 năm trước

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.6

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.7

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.8

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.9

The only filesystem operation that matches the above requirements that I know of is symlink().0

Martijn tại Nowhere dot com ¶

6 năm trước

The only filesystem operation that matches the above requirements that I know of is symlink().1

The only filesystem operation that matches the above requirements that I know of is symlink().2

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

Brospam tại Gmail Dot Com ¶

Erickson Reyes ercbluemonday tại yahoo dot com ¶

The only filesystem operation that matches the above requirements that I know of is symlink().4

The only filesystem operation that matches the above requirements that I know of is symlink().5

The only filesystem operation that matches the above requirements that I know of is symlink().6

The only filesystem operation that matches the above requirements that I know of is symlink().7

The only filesystem operation that matches the above requirements that I know of is symlink().8

The only filesystem operation that matches the above requirements that I know of is symlink().9

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).0

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).1

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).2

Eight_hf tại Live Dot Fr ¶

10 năm trước

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).3

kroczu tại interia dot pl ¶

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).5

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).6

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).7

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).8

16 năm trước

11 năm trước

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).9

Brooke tại Jump Dot Net

12 năm trước

#!/usr/bin/php
<?php
0

#!/usr/bin/php
<?php
1

#!/usr/bin/php
<?php
2

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

Martijn tại Nowhere dot com ¶

6 năm trước

#!/usr/bin/php
<?php
4

#!/usr/bin/php
<?php
5

#!/usr/bin/php
<?php
6

#!/usr/bin/php
<?php
7

#!/usr/bin/php
<?php
8

#!/usr/bin/php
<?php
9

define0

Brospam tại Gmail Dot Com ¶

Erickson Reyes ercbluemonday tại yahoo dot com ¶

12 năm trước

define2

define3

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