switch ([$color, $size]) {
case ['blue', 'small']:
echo 'blue and small';
break;
case ['red', 'large'];
echo 'red and large';
break;
}
switch(true) {
case ($color == 'blue' and $size == 'small'):
echo "blue and small";
break;
case ($color == 'red' and $size == 'large'):
echo "red and large";
break;
default:
echo 'nothing';
break;
}
<button onclick="print()">Файл PDF</button>
function print() {
w = window.open('https://africau.edu/images/default/sample.pdf');
w.print();
}
/usr/bin/flock -w 600 /var/tmp/myscript.lock /root/myscript.sh
Эта комманда запустит /root/myscript.sh и создаст lock-файл для данного процесса. Пока он активен, новый вызов данного скрипта не произойдет.
После завершения программы, блокировка файла снимается и процесс может быть снова запущен.
Параметр -w 600 определяет время ожидания комманды flock на освобождение lock-файла.
Для моментальной отмены выполнения процесса используйте параметр -w 0, для ожидания же бесконечно долгого времени параметр нужно опустить.
ignore_user_abort(true);
header("Connection: close");
header("Content-Length: " . mb_strlen($response));
echo $response;
flush();
do_function_that_takes_five_mins();
/usr/bin/flock -w 600 /var/tmp/myscript.lock /root/myscript.sh
while(true)
{
doWork();
sleep(1);
}
try {
tlgrm('sendMessage', ['text' => 'Само сообщение']);
} catch (Throwable $t) {
tlgrm('sendMessage', ['text' => $t->getMessage()]);
}
try {
// Code that may throw an Exception or Error.
} catch (Throwable $t) {
// Executed only in PHP 7, will not match in PHP 5.x
} catch (Exception $e) {
// Executed only in PHP 5.x, will not be reached in PHP 7
}
<?php
session_start();
function redirectBack($data = null) {
if (isset($data)) {
$_SESSION['answer'] = $data;
} else {
unset($_SESSION['answer']);
}
header('Location: '. $_SERVER['REQUEST_URI']); exit;
}
$login = 'Lane';
$password = 'admin';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty($_POST['login']) || empty($_POST['password'])) {
redirectBack("Something is incorrect...");
}
if ($_POST['login'] != $login || $_POST['password'] != $password) {
redirectBack("Something is incorrect...");
}
redirectBack("The authorization went well!");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="styles.css" rel="stylesheet" />
<title>Project - ведение списков</title>
</head>
<body>
<? if (!empty($_SESSION['answer'])) : ?>
<div class="alert alert-warning" role="alert">
<?= $_SESSION['answer']; ?>
</div>
<? endif; ?>
</body>
</html>