如何限制php函数使用特定数量的RAM?
有没有办法限制php函数使用特定数量的计算机RAM。 本地和服务器上有不同的RAM内存。我想测试它在本地只有1 GB的内存这是可能的,这里是功能如何限制php函数使用特定数量的RAM?,php,memory,Php,Memory,有没有办法限制php函数使用特定数量的计算机RAM。 本地和服务器上有不同的RAM内存。我想测试它在本地只有1 GB的内存这是可能的,这里是功能 public function handle() { $pdfMerger = new PdfMerger(); $bulk_pdf = public_path('bulk-pdf-consignment/manifest' . $this->manifest_
public function handle()
{
$pdfMerger = new PdfMerger();
$bulk_pdf = public_path('bulk-pdf-consignment/manifest' . $this->manifest_id . '_.pdf');
$allFilesPath = public_path('bulk-pdf-consignment/manifest_' . $this->manifest_id);
if (File::exists($bulk_pdf)) {
$pdfMerger->addPDF($bulk_pdf, 'all');
}
$filesInFolder = collect(File::files($allFilesPath))->sortBy(function ($file) {
return $file->getCTime();
});
$arr = [];
$filesCount = 0;
$x = '';
foreach ($filesInFolder as $path) {
$file = pathinfo($path);
$finalPath = $file['dirname'] . '/' . $file['basename'];
$added = $pdfMerger->addPDF($finalPath, 'all');
if ($added) {
array_push($arr, $finalPath);
}
$filesCount++;
echo "real: ".(memory_get_peak_usage(true)/1024/1024)." MiB\n\n";
$x .= str_repeat(' ', 1024*25); //store 25kb more to string
}
$merged = $pdfMerger->merge("file", $bulk_pdf);
if ($merged) {
$url = Storage::disk('s3')->url('bulk_pdf_consignments/manifest' . $this->manifest_id . '_.pdf', fopen($bulk_pdf, 'r+'));
Notification_Helper::sendNotification($this->user_id, 'Download Bulk Print Label PDF'.$filesCount, $url,$this->user_type);
if ($this->user_type == 'staff') {
$user = Staff::find($this->user_id);
}
if ($this->user_type == 'customer') {
$user = Contact::find($this->user_id);
}
sendEmail($user->email, 'Manifest Consignment Labels PDF ', $url, $attachment = null);
// File::delete($bulk_pdf);
// File::deleteDirectory($allFilesPath);
// foreach ($arr as $file) {
File::delete($finalPath);
// }
}
}
我想测试它,因为我在live server上您应该能够设置php内存限制,在脚本顶部添加以下行
ini_set('memory_limit','1G');
此函数设置了RAM分配?这就是我了解itOk的方式,如果函数需要50 Mb RAM,而我们只分配20 Mb RAM,会发生什么情况。它会失败吗?我提供的链接解释了这一点