Execute the command line in Windows 10 and report an error: call to undefined function app\console\commands\POSIX_Getpid()
1. Execute the command line in Windows 10 and report an error: Call to undefined function App\Console\Commands\POSIX_Getpid(). as shown in Figure 1
PS E:\wwwroot\msi_main> php artisan migrate
In ExportRecords.php line 65:
Call to undefined function App\Console\Commands\posix_getpid()
2. Reference URL:https://www.php.net/manual/zh/intro.posix.php. This extension is not available on Windows platforms. You can also try using getMyPid() instead. as shown in Figure 2
3. POSIX_GETPID — Returns the current process ID. Decide to replace with: GetMyPid — Get the id of the PHP process. Reference URL:https://www.php.net/getmypid。
4. Edit /app/console/commands/exportrecords.php . Replace posix_getpid with getMyPID.
private function setLogPrefix() {
// $pid = posix_getpid();
$pid = getmypid();
$ppid = posix_getppid(); //获取父进程id
$this->log_prefix = "CommandExportRecords : pid:{$pid} : ppid:{$ppid} :";
return $this;
}
5. Continue to execute the command line and report an error: call to undefined function app\console\commands\posix_getppid().
PS E:\wwwroot\msi_main> php artisan migrate
In ExportRecords.php line 67:
Call to undefined function App\Console\Commands\posix_getppid()
6. POSIX_Getppid does not work on Windows. This is an alternative. Reference URL:https://www.php.net/manual/zh/function.posix-getppid. Determine if it is a Windows system, if so, use an alternative. as shown in Figure 3
private function setLogPrefix() {
if(strncasecmp(PHP_OS, "win", 3) == 0) {
$pid = getmypid(); // child process ID
$ppid = shell_exec("wmic process where (processid=$pid) get parentprocessid");
$ppid = explode("\n", $ppid);
$ppid = intval($ppid[1]);
} else {
$pid = posix_getpid();
$ppid = posix_getppid(); //获取父进程id
}
$this->log_prefix = "CommandExportRecords : pid:{$pid} : ppid:{$ppid} :";
return $this;
}
7. Continue to execute the command line, no errors are reported again. as shown in Figure 4
PS E:\wwwroot\msi_main> php artisan migrate
Migration table created successfully.



