Tag Archives: php

nohup style php

$lock = fopen('/path/to/pid', 'c+');
if (!flock($lock, LOCK_EX | LOCK_NB)) {
die('already running');

switch ($pid = pcntl_fork()) {
case -1:
die('unable to fork');
case 0: // this is the child process
default: // otherwise this is the parent process
fseek($lock, 0);
ftruncate($lock, 0);
fwrite($lock, $pid);

if (posix_setsid() === -1) {
die('could not setsid');


$stdIn = fopen('/dev/null', 'r'); // set fd/0
$stdOut = fopen('/dev/null', 'w'); // set fd/1
$stdErr = fopen('php://stdout', 'w'); // a hack to duplicate fd/1 to 2

pcntl_signal(SIGTSTP, SIG_IGN);
pcntl_signal(SIGTTOU, SIG_IGN);
pcntl_signal(SIGTTIN, SIG_IGN);
pcntl_signal(SIGHUP, SIG_IGN);

// do some staff

// to kill the proccess
$lock = fopen(‘/path/to/pid’, ‘c+’);
if (flock($lock, LOCK_EX | LOCK_NB)) {
die(‘process not running’);
$pid = fgets($lock);

posix_kill($pid, SIGTERM);

ubuntu php 7.3

LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
apt update
apt install php7.3 php7.3-cli php7.3-common

php -v
PHP 7.3.20-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jul 9 2020 16:33:48) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.20, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.20-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

laravel hacked database

Its serious security issue this default Laravel configuration. because .env file and database credentials are not protected. So you need to create a .htaccess file in same folder to protect it:

<Files .env>
order allow,deny
Deny from all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

yum install php without httpd

yum install php-cli

php-cli x86_64 7.3.18-1.el6.remi remi-php73 4.4 M
Installing for dependencies:
libargon2 x86_64 20161029-7.el6.remi remi 21 k
php-common x86_64 7.3.18-1.el6.remi remi-php73 1.1 M
php-json x86_64 7.3.18-1.el6.remi remi-php73 65 k

Transaction Summary
Install 4 Package(s)
Total download size: 5.6 M