Working with files
Create file
$file = fopen("test.txt", "w"); // w = write mode (overwrites)
fwrite($file, "Hello World");
fclose($file);
Append to file
file_put_contents("test.txt", "More text\n", FILE_APPEND);
Functions
fopen() → open files
fwrite() → write to file
file_put_contents() → write/append in one call
strlen() → get string length
Run Multiple PHP Scripts at the same time
PHP is single-threaded by default. Options:
- Background execution:
exec("php script.php > /dev/null &");
- Multi-process:
pcntl_fork() (CLI only, not in web server)
- Async frameworks: ReactPHP, AMP
- HTTP parallel:
curl_multi_* functions
- Task queues: Gearman, RabbitMQ, Swoole
Find running scripts in Linux:
ps aux | grep php