我在Laravel控制器中收到错误消息:proc_open(): fork failed - Cannot allocate memory
。使用axios(Vuejs SAP)调用generate
函数。
这就是我的控制器的样子
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use GifCreator\AnimGif;
use simpleimage\SimpleImage;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class GifController extends Controller
{
//
public function generate(Request $request)
{
if(!$request->ajax()) return;
$cmd = 'ls';
$process = new Process($cmd);
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
}
}
服务器上的 free -m
:
| | total | used | free | shared | buff/cache | available |
| ----- | ------ | ----- | ---- | ------ | ---------- | --------- |
| Mem: | 2000 | 243 | 577 | 20 | 1178 | 1541 |
| Swap: | 4095 | 0 | 4095 | | | |
修改
正如Hilmi指出我现在尝试添加交换空间,现在命令成功运行有时 - 大约一半时间。
如果进程失败,有没有办法重试进程?