In Linux C Programming, everyone knows to create a file in a process, keep it open, and unlink the file. It does not actually delete it, but waits until the process ends, all FD are disabled before they are actually cleared. In PHP, the same operation method is used to get a PID file that identifies a process that is still running! In PHP, if a file is created and the reference pointer of the file is retained, the unlink file cannot be created, and the following error occurs: Warning: unlink permiss denied. If the file pointer is not retained or unset, the file is deleted immediately, instead of waiting until the process ends. That is, PHP does not allow you to delete objects that still reference pointers compared with C programming. The following is the PHP and C code: PHP:
|
<?php
$filename = "/tmp/test_php.pid";
$fp = fopen($filename, 'w');
//unset($fp);
unlink($filename);
sleep(6);
|
C:
|
#include <stdio.h>
int main()
{
char *filename = "/tmp/test_c.pid";
FILE *fp;
fp = fopen(filename, "w");
unlink(filename);
sleep(6);
}
|