Use Alibaba Cloud Performance Testing PTS to simulate concurrent HTTP requests
1. Decide to simulate the case of using file_put_contents() to write the same path file in the test environment at the same time, and then observe whether the read file content is empty.
require.php
<?php
$i = rand();
$path = 'return.php';
$contents = [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j'
];
if (file_exists($path)) {
$read = file_get_contents($path);
if (empty($read)) {
file_put_contents('empty-' . rand() . '.php', $read, LOCK_EX);
}
}
$code = '<?php';
$code .= "\n\n";
$contents = array_merge($contents, [$i]);
$code .= 'return ' . var_export($contents, true) . ';';
file_put_contents($path, $code, LOCK_EX);
?>
2. Since it is only temporarily used, the product type can be deducted from the resource package by quantity, and the experience version of the resource package type is selected, and at the same time, it simulates a maximum of 1,000 virtual users. as shown in Figure 1
3. Create a test scenario, select the pressure mode concurrent mode (virtual user mode), increase mode Manual speed regulation, the maximum concurrency is 10, the total pressure test time is 2 minutes, and the estimated consumption is 1000vum. as shown in Figure 2
4. Interface test, select the scene just created, performance test PTS / pressure test. as shown in Figure 3
5. View the performance test PTS/report details, the total number of requests is 4.9W. as shown in Figure 4
6. Check the running results of the program, and it is determined that more than 20,000 files are generated, namely: return.php, and a large number of files starting with empty-. as shown in Figure 5




