search
HomeBackend DevelopmentPHP TutorialPHP writing daemon (Daemon)_PHP tutorial

PHP writing daemon (Daemon)_PHP tutorial

Jul 15, 2016 pm 01:21 PM
phpWriteBackstagecontrolyesofprocess

Daemon is a special process running in the background. It is independent of the control terminal and periodically performs some task or waits for some event to occur. Daemon is a very useful process. PHP can also implement the function of daemon process.

1. Basic concepts

Process

Each process has a parent process. When the child process exits, the parent process can get the exit status of the child process.

Process Group

Each process belongs to a process group, and each process group has a process group number, which is equal to the PID of the process group leader

2. Key points of daemon programming

Daemon is a special process running in the background. It is independent of the control terminal and periodically performs some task or waits for some event to occur. Daemon is a very useful process. PHP can also implement the function of daemon process.

1. Basic concepts

Process

Each process has a parent process. When the child process exits, the parent process can get the exit status of the child process.

Process Group

Each process belongs to a process group, and each process group has a process group number, which is equal to the PID of the process group leader

2. Key points of daemon programming

1. Run in the background. 
To avoid hanging the control terminal, put Daemon into the background for execution. The method is to call fork in the process to terminate the parent process and let Daemon execute in the background in the child process. if($pid=pcntl_fork()) exit(0);//It is the parent process, end the parent process, and the child process continues
2. Get rid of the controlling terminal and log in to the session and process group
It is necessary to first introduce the relationship between processes and control terminals, login sessions and process groups in Linux: a process belongs to a process group, and the process group number (GID) is the process number (PID) of the process group leader. A login session can contain multiple process groups. These process groups share a controlling terminal. This control terminal is usually the login terminal where the process was created. Controlling terminals, login sessions, and process groups are usually inherited from the parent process. Our purpose is to get rid of them and not be affected by them. The method is to call setsid() based on point 1 to make the process the session leader: posix_setsid();
​ ​ ​ Description: The setsid() call fails when the process is the session leader. But the first point already ensures that the process is not the session leader. After the setsid() call is successful, the process becomes the new session group leader and new process group leader, and is separated from the original login session and process group. Due to the exclusivity of the session process to the control terminal, the process is detached from the control terminal at the same time.
3. Disable the process from reopening the control terminal
Now, the process has become the terminalless session leader. But it can be re-applied to open a control terminal. You can prevent the process from reopening the control terminal by making the process no longer the session leader: if($pid=pcntl_fork()) exit(0);//End the first child process and the second child process continues (the second child process No longer the conversation leader)
4. Close the open file descriptor
A process inherits open file descriptors from the parent process that created it. If it is not closed, system resources will be wasted, the file system where the process is located will not be able to be unmounted, and unpredictable errors will occur. Close them as follows:
                fclose(STDIN), fclose(STDOUT), fclose(STDERR) closes standard input, output and error display.
5. Change the current working directory
When a process is active, the file system where its working directory is located cannot be unmounted. Generally you need to change the working directory to the root directory. For core dumps that need to be dumped, the process writing the running log changes the working directory to a specific directory such as chdir("/")
6. Reset file creation mask
A process inherits the file creation mask from the parent process that created it. It may modify the access bits of files created by the daemon. To prevent this, clear the file creation mask: umask(0);
7. Processing SIGCHLD signal
It is not necessary to handle the SIGCHLD signal. But for some processes, especially server processes, child processes are often generated to handle requests when requests arrive. If the parent process does not wait for the child process to end, the child process will become a zombie process (zombie) and occupy system resources. If the parent process waits for the child process to end, it will increase the burden on the parent process and affect the concurrency performance of the server process. Under Linux, you can simply set the operation of the SIGCHLD signal to SIG_IGN. signal(SIGCHLD,SIG_IGN);
This way, the kernel will not create a zombie process when the child process ends. This is different from BSD4. Under BSD4, you must explicitly wait for the child process to end before releasing the zombie process. For questions about signals, please refer to the Linux signal description list


3. Example

 
<?php  
/** 
*@author tengzhaorong@gmail.com 
*@date 2013-07-25 
* 后台脚本控制类 
*/  
class DaemonCommand{  
   
    private $info_dir="/tmp";  
    private $pid_file="";  
    private $terminate=false; //是否中断   
    private $workers_count=0;  
    private $gc_enabled=null;  
    private $workers_max=8; //最多运行8个进程   
   
    public function __construct($is_sington=false,$user=&#39;nobody&#39;,$output="/dev/null"){  
   
            $this->is_sington=$is_sington; //是否单例运行,单例运行会在tmp目录下建立一个唯一的PID   
            $this->user=$user;//设置运行的用户 默认情况下nobody   
            $this->output=$output; //设置输出的地方   
            $this->checkPcntl();  
    }  
    //检查环境是否支持pcntl支持   
    public function checkPcntl(){  
        if ( ! function_exists(&#39;pcntl_signal_dispatch&#39;)) {  
            // PHP < 5.3 uses ticks to handle signals instead of pcntl_signal_dispatch   
            // call sighandler only every 10 ticks   
            declare(ticks = 10);  
        }  
   
        // Make sure PHP has support for pcntl   
        if ( ! function_exists(&#39;pcntl_signal&#39;)) {  
            $message = &#39;PHP does not appear to be compiled with the PCNTL extension.  This is neccesary for daemonization&#39;;  
            $this->_log($message);  
            throw new Exception($message);  
        }  
        //信号处理   
        pcntl_signal(SIGTERM, array(__CLASS__, "signalHandler"),false);  
        pcntl_signal(SIGINT, array(__CLASS__, "signalHandler"),false);  
        pcntl_signal(SIGQUIT, array(__CLASS__, "signalHandler"),false);  
   
        // Enable PHP 5.3 garbage collection   
        if (function_exists(&#39;gc_enable&#39;))  
        {  
            gc_enable();  
            $this->gc_enabled = gc_enabled();  
        }  
    }  
   
    // daemon化程序   
    public function daemonize(){  
   
        global $stdin, $stdout, $stderr;  
        global $argv;  
   
        set_time_limit(0);  
   
        // 只允许在cli下面运行   
        if (php_sapi_name() != "cli"){  
            die("only run in command line mode\n");  
        }  
   
        // 只能单例运行   
        if ($this->is_sington==true){  
   
            $this->pid_file = $this->info_dir . "/" .__CLASS__ . "_" . substr(basename($argv[0]), 0, -4) . ".pid";  
            $this->checkPidfile();  
        }  
   
        umask(0); //把文件掩码清0   
   
        if (pcntl_fork() != 0){ //是父进程,父进程退出   
            exit();  
        }  
   
        posix_setsid();//设置新会话组长,脱离终端   
   
        if (pcntl_fork() != 0){ //是第一子进程,结束第一子进程      
            exit();  
        }  
   
        chdir("/"); //改变工作目录   
   
        $this->setUser($this->user) or die("cannot change owner");  
   
        //关闭打开的文件描述符   
        fclose(STDIN);  
        fclose(STDOUT);  
        fclose(STDERR);  
   
        $stdin  = fopen($this->output, &#39;r&#39;);  
        $stdout = fopen($this->output, &#39;a&#39;);  
        $stderr = fopen($this->output, &#39;a&#39;);  
   
        if ($this->is_sington==true){  
            $this->createPidfile();  
        }  
   
    }  
    //--检测pid是否已经存在   
    public function checkPidfile(){  
   
        if (!file_exists($this->pid_file)){  
            return true;  
        }  
        $pid = file_get_contents($this->pid_file);  
        $pid = intval($pid);  
        if ($pid > 0 && posix_kill($pid, 0)){  
            $this->_log("the daemon process is already started");  
        }  
        else {  
            $this->_log("the daemon proces end abnormally, please check pidfile " . $this->pid_file);  
        }  
        exit(1);  
   
    }  
    //----创建pid   
    public function createPidfile(){  
   
        if (!is_dir($this->info_dir)){  
            mkdir($this->info_dir);  
        }  
        $fp = fopen($this->pid_file, &#39;w&#39;) or die("cannot create pid file");  
        fwrite($fp, posix_getpid());  
        fclose($fp);  
        $this->_log("create pid file " . $this->pid_file);  
    }  
   
    //设置运行的用户   
    public function setUser($name){  
   
        $result = false;  
        if (empty($name)){  
            return true;  
        }  
        $user = posix_getpwnam($name);  
        if ($user) {  
            $uid = $user[&#39;uid&#39;];  
            $gid = $user[&#39;gid&#39;];  
            $result = posix_setuid($uid);  
            posix_setgid($gid);  
        }  
        return $result;  
   
    }  
    //信号处理函数   
    public function signalHandler($signo){  
   
        switch($signo){  
   
            //用户自定义信号   
            case SIGUSR1: //busy   
            if ($this->workers_count < $this->workers_max){  
                $pid = pcntl_fork();  
                if ($pid > 0){  
                    $this->workers_count ++;  
                }  
            }  
            break;  
            //子进程结束信号   
            case SIGCHLD:  
                while(($pid=pcntl_waitpid(-1, $status, WNOHANG)) > 0){  
                    $this->workers_count --;  
                }  
            break;  
            //中断进程   
            case SIGTERM:  
            case SIGHUP:  
            case SIGQUIT:  
   
                $this->terminate = true;  
            break;  
            default:  
            return false;  
        }  
   
    }  
    /** 
    *开始开启进程 
    *$count 准备开启的进程数 
    */  
    public function start($count=1){  
   
        $this->_log("daemon process is running now");  
        pcntl_signal(SIGCHLD, array(__CLASS__, "signalHandler"),false); // if worker die, minus children num   
        while (true) {  
            if (function_exists(&#39;pcntl_signal_dispatch&#39;)){  
   
                pcntl_signal_dispatch();  
            }  
   
            if ($this->terminate){  
                break;  
            }  
            $pid=-1;  
            if($this->workers_count<$count){  
   
                $pid=pcntl_fork();  
            }  
   
            if($pid>0){  
   
                $this->workers_count++;  
   
            }elseif($pid==0){  
   
                // 这个符号表示恢复系统对信号的默认处理   
                pcntl_signal(SIGTERM, SIG_DFL);  
                pcntl_signal(SIGCHLD, SIG_DFL);  
                if(!empty($this->jobs)){  
                    while($this->jobs[&#39;runtime&#39;]){  
                        if(empty($this->jobs[&#39;argv&#39;])){  
                            call_user_func($this->jobs[&#39;function&#39;],$this->jobs[&#39;argv&#39;]);  
                        }else{  
                            call_user_func($this->jobs[&#39;function&#39;]);  
                        }  
                        $this->jobs[&#39;runtime&#39;]--;  
                        sleep(2);  
                    }  
                    exit();  
   
                }  
                return;  
   
            }else{  
   
                sleep(2);  
            }  
   
   
        }  
   
        $this->mainQuit();  
        exit(0);  
   
    }  
   
    //整个进程退出   
    public function mainQuit(){  
   
        if (file_exists($this->pid_file)){  
            unlink($this->pid_file);  
            $this->_log("delete pid file " . $this->pid_file);  
        }  
        $this->_log("daemon process exit now");  
        posix_kill(0, SIGKILL);  
        exit(0);  
    }  
   
    // 添加工作实例,目前只支持单个job工作   
    public function setJobs($jobs=array()){  
   
        if(!isset($jobs[&#39;argv&#39;])||empty($jobs[&#39;argv&#39;])){  
   
            $jobs[&#39;argv&#39;]="";  
   
        }  
        if(!isset($jobs[&#39;runtime&#39;])||empty($jobs[&#39;runtime&#39;])){  
   
            $jobs[&#39;runtime&#39;]=1;  
   
        }  
   
        if(!isset($jobs[&#39;function&#39;])||empty($jobs[&#39;function&#39;])){  
   
            $this->log("你必须添加运行的函数!");  
        }  
   
        $this->jobs=$jobs;  
   
    }  
    //日志处理   
    private  function _log($message){  
        printf("%s\t%d\t%d\t%s\n", date("c"), posix_getpid(), posix_getppid(), $message);  
    }  
   
}  
   
//调用方法1   
$daemon=new DaemonCommand(true);  
$daemon->daemonize();  
$daemon->start(2);//开启2个子进程工作   
work();  
   
   
   
   
//调用方法2   
$daemon=new DaemonCommand(true);  
$daemon->daemonize();  
$daemon->addJobs(array(&#39;function&#39;=>&#39;work&#39;,&#39;argv&#39;=>&#39;&#39;,&#39;runtime&#39;=>1000));//function 要运行的函数,argv运行函数的参数,runtime运行的次数   
$daemon->start(2);//开启2个子进程工作   
   
//具体功能的实现   
function work(){  
      echo "测试1";  
}  
?>  

<?php
/**
*@author tengzhaorong@gmail.com
*@date 2013-07-25
* 后台脚本控制类
*/
class DaemonCommand{
 
    private $info_dir="/tmp";
    private $pid_file="";
    private $terminate=false; //是否中断
    private $workers_count=0;
    private $gc_enabled=null;
    private $workers_max=8; //最多运行8个进程
 
    public function __construct($is_sington=false,$user=&#39;nobody&#39;,$output="/dev/null"){
 
            $this->is_sington=$is_sington; //是否单例运行,单例运行会在tmp目录下建立一个唯一的PID
            $this->user=$user;//设置运行的用户 默认情况下nobody
            $this->output=$output; //设置输出的地方
            $this->checkPcntl();
    }
    //检查环境是否支持pcntl支持
    public function checkPcntl(){
        if ( ! function_exists(&#39;pcntl_signal_dispatch&#39;)) {
            // PHP < 5.3 uses ticks to handle signals instead of pcntl_signal_dispatch
            // call sighandler only every 10 ticks
            declare(ticks = 10);
        }
 
        // Make sure PHP has support for pcntl
        if ( ! function_exists(&#39;pcntl_signal&#39;)) {
            $message = &#39;PHP does not appear to be compiled with the PCNTL extension.  This is neccesary for daemonization&#39;;
            $this->_log($message);
            throw new Exception($message);
        }
        //信号处理
        pcntl_signal(SIGTERM, array(__CLASS__, "signalHandler"),false);
        pcntl_signal(SIGINT, array(__CLASS__, "signalHandler"),false);
        pcntl_signal(SIGQUIT, array(__CLASS__, "signalHandler"),false);
 
        // Enable PHP 5.3 garbage collection
        if (function_exists(&#39;gc_enable&#39;))
        {
            gc_enable();
            $this->gc_enabled = gc_enabled();
        }
    }
 
    // daemon化程序
    public function daemonize(){
 
        global $stdin, $stdout, $stderr;
        global $argv;
 
        set_time_limit(0);
 
        // 只允许在cli下面运行
        if (php_sapi_name() != "cli"){
            die("only run in command line mode\n");
        }
 
        // 只能单例运行
        if ($this->is_sington==true){
 
            $this->pid_file = $this->info_dir . "/" .__CLASS__ . "_" . substr(basename($argv[0]), 0, -4) . ".pid";
            $this->checkPidfile();
        }
 
        umask(0); //把文件掩码清0
 
        if (pcntl_fork() != 0){ //是父进程,父进程退出
            exit();
        }
 
        posix_setsid();//设置新会话组长,脱离终端
 
        if (pcntl_fork() != 0){ //是第一子进程,结束第一子进程   
            exit();
        }
 
        chdir("/"); //改变工作目录
 
        $this->setUser($this->user) or die("cannot change owner");
 
        //关闭打开的文件描述符
        fclose(STDIN);
        fclose(STDOUT);
        fclose(STDERR);
 
        $stdin  = fopen($this->output, &#39;r&#39;);
        $stdout = fopen($this->output, &#39;a&#39;);
        $stderr = fopen($this->output, &#39;a&#39;);
 
        if ($this->is_sington==true){
            $this->createPidfile();
        }
 
    }
    //--检测pid是否已经存在
    public function checkPidfile(){
 
        if (!file_exists($this->pid_file)){
            return true;
        }
        $pid = file_get_contents($this->pid_file);
        $pid = intval($pid);
        if ($pid > 0 && posix_kill($pid, 0)){
            $this->_log("the daemon process is already started");
        }
        else {
            $this->_log("the daemon proces end abnormally, please check pidfile " . $this->pid_file);
        }
        exit(1);
 
    }
    //----创建pid
    public function createPidfile(){
 
        if (!is_dir($this->info_dir)){
            mkdir($this->info_dir);
        }
        $fp = fopen($this->pid_file, &#39;w&#39;) or die("cannot create pid file");
        fwrite($fp, posix_getpid());
        fclose($fp);
        $this->_log("create pid file " . $this->pid_file);
    }
 
    //设置运行的用户
    public function setUser($name){
 
        $result = false;
        if (empty($name)){
            return true;
        }
        $user = posix_getpwnam($name);
        if ($user) {
            $uid = $user[&#39;uid&#39;];
            $gid = $user[&#39;gid&#39;];
            $result = posix_setuid($uid);
            posix_setgid($gid);
        }
        return $result;
 
    }
    //信号处理函数
    public function signalHandler($signo){
 
        switch($signo){
 
            //用户自定义信号
            case SIGUSR1: //busy
            if ($this->workers_count < $this->workers_max){
                $pid = pcntl_fork();
                if ($pid > 0){
                    $this->workers_count ++;
                }
            }
            break;
            //子进程结束信号
            case SIGCHLD:
                while(($pid=pcntl_waitpid(-1, $status, WNOHANG)) > 0){
                    $this->workers_count --;
                }
            break;
            //中断进程
            case SIGTERM:
            case SIGHUP:
            case SIGQUIT:
 
                $this->terminate = true;
            break;
            default:
            return false;
        }
 
    }
    /**
    *开始开启进程
    *$count 准备开启的进程数
    */
    public function start($count=1){
 
        $this->_log("daemon process is running now");
        pcntl_signal(SIGCHLD, array(__CLASS__, "signalHandler"),false); // if worker die, minus children num
        while (true) {
            if (function_exists(&#39;pcntl_signal_dispatch&#39;)){
 
                pcntl_signal_dispatch();
            }
 
            if ($this->terminate){
                break;
            }
            $pid=-1;
            if($this->workers_count<$count){
 
                $pid=pcntl_fork();
            }
 
            if($pid>0){
 
                $this->workers_count++;
 
            }elseif($pid==0){
 
                // 这个符号表示恢复系统对信号的默认处理
                pcntl_signal(SIGTERM, SIG_DFL);
                pcntl_signal(SIGCHLD, SIG_DFL);
                if(!empty($this->jobs)){
                    while($this->jobs[&#39;runtime&#39;]){
                        if(empty($this->jobs[&#39;argv&#39;])){
                            call_user_func($this->jobs[&#39;function&#39;],$this->jobs[&#39;argv&#39;]);
                        }else{
                            call_user_func($this->jobs[&#39;function&#39;]);
                        }
                        $this->jobs[&#39;runtime&#39;]--;
                        sleep(2);
                    }
                    exit();
 
                }
                return;
 
            }else{
 
                sleep(2);
            }
 
 
        }
 
        $this->mainQuit();
        exit(0);
 
    }
 
    //整个进程退出
    public function mainQuit(){
 
        if (file_exists($this->pid_file)){
            unlink($this->pid_file);
            $this->_log("delete pid file " . $this->pid_file);
        }
        $this->_log("daemon process exit now");
        posix_kill(0, SIGKILL);
        exit(0);
    }
 
    // 添加工作实例,目前只支持单个job工作
    public function setJobs($jobs=array()){
 
        if(!isset($jobs[&#39;argv&#39;])||empty($jobs[&#39;argv&#39;])){
 
            $jobs[&#39;argv&#39;]="";
 
        }
        if(!isset($jobs[&#39;runtime&#39;])||empty($jobs[&#39;runtime&#39;])){
 
            $jobs[&#39;runtime&#39;]=1;
 
        }
 
        if(!isset($jobs[&#39;function&#39;])||empty($jobs[&#39;function&#39;])){
 
            $this->log("你必须添加运行的函数!");
        }
 
        $this->jobs=$jobs;
 
    }
    //日志处理
    private  function _log($message){
        printf("%s\t%d\t%d\t%s\n", date("c"), posix_getpid(), posix_getppid(), $message);
    }
 
}
 
//调用方法1
$daemon=new DaemonCommand(true);
$daemon->daemonize();
$daemon->start(2);//开启2个子进程工作
work();
 
 
 
 
//调用方法2
$daemon=new DaemonCommand(true);
$daemon->daemonize();
$daemon->addJobs(array(&#39;function&#39;=>&#39;work&#39;,&#39;argv&#39;=>&#39;&#39;,&#39;runtime&#39;=>1000));//function 要运行的函数,argv运行函数的参数,runtime运行的次数
$daemon->start(2);//开启2个子进程工作
 
//具体功能的实现
function work(){
      echo "测试1";
}
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477175.htmlTechArticleDaemon is a special process running in the background. It is independent of the control terminal and periodically performs some task or waits for some event to occur. A daemon is a...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software