出现这个错误消息,有什么建议吗?

允许内存大小为33554432字节已耗尽(已尝试分配 43148176字节)的PHP


当前回答

如果您试图读取一个文件,这将占用PHP中的内存。例如,如果您试图打开并读取一个MP3文件(例如,$data = file("http://mydomain.com/path/sample.mp3")),它将把它全部拉到内存中。

正如Nelson所建议的,如果您确实需要使用这么多内存,您可以提高您的最大内存限制。

其他回答

在Wordpress中切换到一个新主题后,我收到了同样的错误信息。PHP运行的是5.3版本,所以我切换到了7.2。这解决了问题。

如果你正在使用Laravel,那么可以使用以下方法:

public function getClientsListApi(Request $request){
      print_r($request->all()); //for all request
      print_r($request->name); //for all name 
}

而不是

public function getClientsListApi(Request $request){
      print_r($request); // it show error as above mention
}

It is unfortunately easy to program in PHP in a way that consumes memory faster than you realise. Copying strings, arrays and objects instead of using references will do it, though PHP 5 is supposed to do this more automatically than in PHP 4. But dealing with your data set in entirety over several steps is also wasteful compared to processing the smallest logical unit at a time. The classic example is working with large resultsets from a database: most programmers fetch the entire resultset into an array and then loop over it one or more times with foreach(). It is much more memory efficient to use a while() loop to fetch and process one row at a time. The same thing applies to processing a file.

我没有更新主机,数据库是只读的。Joomla需要编写会话,但无法完成。

如果你想读取大文件,你应该一点一点地读取,而不是一次读取。 这是一个简单的数学:如果您一次读取一个1mb大的文件,那么同时至少需要1mb的内存来保存数据。

所以你应该使用fopen & fread一点一点地阅读它们。