sha1_file
(PHP 4 >= 4.3.0, PHP 5)
sha1_file — 计算文件的 sha1 散列值
说明
string sha1_file ( string $filename [, bool $raw_output = false ] )利用» 美国安全散列算法 1,计算并返回由 filename 指定的文件的 sha1 散列值。该散列值是一个 40 字符长度的十六进制数字。
参数
- filename
-
要散列的文件的文件名。
- raw_output
-
如果被设置为 TRUE,sha1 摘要将以 20 字符长度的原始格式返回。
返回值
成功返回一个字符串,否则返回 FALSE。
范例
Example #1 sha1_file() 范例
<?php
foreach(glob('/home/Kalle/myproject
$domain = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' ? AF_INET : AF_UNIX);
if (socket_create_pair($domain, SOCK_STREAM, 0, $sockets) === false) {
echo "socket_create_pair failed. Reason: ".socket_strerror(socket_last_error());
}
if (socket_write($sockets[0], "ABCdef123
", strlen("ABCdef123
")) === false) {
echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($sockets[0]));
}
if (($data = socket_read($sockets[1], strlen("ABCdef123
"), PHP_BINARY_READ)) === false) {
echo "socket_read() failed. Reason: ".socket_strerror(socket_last_error($sockets[1]));
}
var_dump($data);
socket_close($sockets[0]);
socket_close($sockets[1]);
?>
Example #2 socket_create_pair() IPC example
<?php
$ary = array();
$strone = 'Message From Parent.';
$strtwo = 'Message From Child.';
if (socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $ary) === false) {
echo "socket_create_pair() failed. Reason: ".socket_strerror(socket_last_error());
}
$pid = pcntl_fork();
if ($pid == -1) {
echo 'Could not fork Process.';
} elseif ($pid) {
socket_close($ary[0]);
if (socket_write($ary[1], $strone, strlen($strone)) === false) {
echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($ary[1]));
}
if (socket_read($ary[1], strlen($strtwo), PHP_BINARY_READ) == $strtwo) {
echo "Recieved $strtwo
";
}
socket_close($ary[1]);
} else {
socket_close($ary[1]);
if (socket_write($ary[0], $strtwo, strlen($strtwo)) === false) {
echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($ary[0]));
}
if (socket_read($ary[0], strlen($strone), PHP_BINARY_READ) == $strone) {
echo "Recieved $strone
";
}
socket_close($ary[0]);
}
?>
参见
- socket_create() - Create a socket (endpoint for communication)
- socket_create_listen() - Opens a socket on port to accept connections
- socket_bind() - Binds a name to a socket
- socket_listen() - Listens for a connection on a socket
- socket_last_error() - Returns the last error on the socket
- socket_strerror() - Return a string describing a socket error