ในการเรียกไฟล์ Python จากภายในไฟล์ PHP คุณต้องเรียกมันโดยใช้ฟังก์ชัน shell_exec
ตัวอย่าง
<?php
$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?> สิ่งนี้จะเรียกสคริปต์ แต่ในสคริปต์ของคุณที่ด้านบน คุณจะต้องระบุล่ามด้วย ดังนั้นในไฟล์ py ของคุณ ให้เพิ่มบรรทัดต่อไปนี้ที่ด้านบน:
#!/usr/bin/env python
หรือคุณอาจจัดเตรียมล่ามไว้เมื่อดำเนินการคำสั่ง
ตัวอย่าง
<?php
$command = escapeshellcmd('python3 /usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>