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;
}
add_action( 'wpcf7_before_send_mail',
function( $contact_form, &$abort, $submission ) {
// Getting user input through the your-email field
$your_email = $submission->get_posted_data( 'your-email' );
// Getting user input through the your-message field
$your_message = $submission->get_posted_data( 'your-message' );
// Do some productive things here
},
10, 3
);
<button onclick="print()">Файл PDF</button>
function print() {
w = window.open('https://africau.edu/images/default/sample.pdf');
w.print();
}
add_action( 'wpcf7_before_send_mail',
function( $contact_form, &$abort, $submission ) {
// Getting user input through the your-email field
$your_email = $submission->get_posted_data( 'your-email' );
// Getting user input through the your-message field
$your_message = $submission->get_posted_data( 'your-message' );
// Do some productive things here
},
10, 3
);
/usr/bin/flock -w 600 /var/tmp/myscript.lock /root/myscript.sh
Эта комманда запустит /root/myscript.sh и создаст lock-файл для данного процесса. Пока он активен, новый вызов данного скрипта не произойдет.
После завершения программы, блокировка файла снимается и процесс может быть снова запущен.
Параметр -w 600 определяет время ожидания комманды flock на освобождение lock-файла.
Для моментальной отмены выполнения процесса используйте параметр -w 0, для ожидания же бесконечно долгого времени параметр нужно опустить.
public static function findToken($token)
{
if (strpos($token, '|') === false) {
return static::where('token', hash('sha256', $token))->first();
}
[$id, $token] = explode('|', $token, 2);
if ($instance = static::find($id)) {
return hash_equals($instance->token, hash('sha256', $token)) ? $instance : null;
}
}
ignore_user_abort(true);
header("Connection: close");
header("Content-Length: " . mb_strlen($response));
echo $response;
flush();
do_function_that_takes_five_mins();
....
RUN curl -LO https://deployer.org/deployer.phar && \
mv deployer.phar /usr/local/bin/dep && \
chmod +x /usr/local/bin/dep
....
RUN dep test
/usr/bin/flock -w 600 /var/tmp/myscript.lock /root/myscript.sh
while(true)
{
doWork();
sleep(1);
}
while(true)
{
doWork();
sleep(1);
}
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php artisan command:start
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
stopwaitsecs=3600
// https://laravel.com/docs/8.x/authentication#invalidating-sessions-on-other-devices
Auth::logoutOtherDevices($currentPassword);
// php artisan make:middleware LogoutUsers
// app/Http/Kernel.php -> $middlewareGroups -> web
<?php
namespace App\Http\Middleware;
use Auth;
use Closure;
class LogoutUsers
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!auth()->check()) {
return $next($request);
}
$user = Auth::user();
if ($user->logout === false) {
$user->update(['logout' => true]);
Auth::logout();
return redirect()->route('login');
}
return $next($request);
}
}
//текущий юзер
$user = Auth::user();
//выход конкретного юзера
$userToLogout = User::find(5);
Auth::setUser($userToLogout);
Auth::logout();
//возвращаем текущего юзера
Auth::setUser($user);
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>