PHP.mk документација

posix_times

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.posix-times.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.posix-times.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
posix_times

Референца за `function.posix-times.php` со подобрена типографија и навигација.

function.posix-times.php

posix_times

(PHP 4, PHP 5, PHP 7, PHP 8)

posix_timesДобиј ги времињата на процесот

= NULL

posix_times(): array|false

Добива информации за моменталната употреба на процесорот.

Параметри

Оваа функција нема параметри.

Вратени вредности

Враќа хеш од низи со информации за моменталната употреба на процесорот. Индексите на хешот се:

  • ticks - бројот на отчукувања на часовникот што поминале од рестартирањето.
  • utime - времето на корисникот што го користи тековниот процес.
  • stime - системското време што го користи тековниот процес.
  • cutime - времето на корисникот што го користат тековниот процес и неговите деца.
  • cstime - системското време што го користат тековниот процес и неговите деца.
Вредност на алфа компонентата. false при неуспех.

Примери

Пример #1 Пример за употреба на posix_times()

<?php

$times
= posix_times();

print_r($times);
?>

Горниот пример ќе прикаже нешто слично на:

Array
(
    [ticks] => 25814410
    [utime] => 1
    [stime] => 1
    [cutime] => 0
    [cstime] => 0
)

Белешки

Ги ескејпува специјалните знаци во стринг за употреба во SQL изјава

Оваа функција не е сигурна за употреба, може да врати негативни вредности за високи времиња.

Белешки од корисници 4 белешки

murphy at nmc-online dot co dot uk
пред 22 години
I am not sure why, and it could just be me but on my FreeBSD system using
$time = posix_times();
$time['ticks'] is an enormous value that bears no relation to the system uptime (I tested by rebooting the system,  the number does not change).
I checked my timecounters, they tick every 10.000msec and I did the maths on the returned value and it suggested the machine had been up for over 200 days - it was reformatted about a week ago.
This could be to do with FreeBSD, or *BSD, or just *idiots like me but just check before you use the function.
 ~
FreeBSD 5.1-R, Apache 2.0.46, PHP4.3.2
brain at winbot dot co dot uk
21 години пред
doesnt work with freebsd. as stated above the clock ticks at different intervals on different platforms.

for system uptime consider piping the uptime command or similar, depending on if performance is an issue or not.
not_rich_yet at hotmail dot com
пред 22 години
If you want the output to be 'grammatically correct' then try the following code.  It will eg print '1 minute' as opposed to '1 minutes', the same goes for days and hours:

Put the following code somewhere in the head of the page code:

<?php
function uptime() {
if (!$times = posix_times() ) {
return ("unknown");
} else {
$now = $times['ticks'];
$days = intval($now / (60*60*24*100));
$remainder = $now % (60*60*24*100);
$hours = intval($remainder / (60*60*100));
$remainder = $remainder % (60*60*100);
$minutes = intval($remainder / (60*100));
if ($days == 1) {$writeDays = "day";} else {$writeDays = "days";}
if ($hours == 1) {$writeHours = "hour"; } else {$writeHours = "hours";}
if ($minutes == 1) {$writeMins = "minute";} else {$writeMins = "minutes";}
return ("$days $writeDays, $hours $writeHours, $minutes $writeMins");
}
}
?>

Then put this bit where you want the info displayed:

<?php
print uptime();
?>

Regards,

nry
rossz+php at vamos-wentworth dot org
пред 23 години
This function will return the system uptime as a human readable string such as "172 days, 18 hours, 15 minutes".  I didn't bother to handle singular so the grammar could be a bit off, e.g. 1 hours.

function uptime() {
  if (!$times = posix_times()) {
    return ("unknown");
  } else {
    $now = $times['ticks'];
    $days = intval($now / (60*60*24*100));
    $remainder = $now % (60*60*24*100);
    $hours = intval($remainder / (60*60*100));
    $remainder = $remainder % (60*60*100);
    $minutes = intval($remainder / (60*100));
    return ("$days days, $hours hours, $minutes minutes");
  }
}
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.