如何在drupal中编程生成大量节点时避免“内存不足”错误? [英] how to avoid 'out of memory' errors when programmatically generating a lot of nodes in drupal?

查看:187
本文介绍了如何在drupal中编程生成大量节点时避免“内存不足”错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式创建了大约150个节点,并且在单个请求中执行所有操作时都会运行到内存不足错误。 (我有一个菜单回调,生成节点并调用node_save())。



示例:



<$ ($ i = 0; $ i <150; $ i ++){
$ node = new stdClass(); p $ p>
$ node-> title =Foo $ i;
$ node-> field_myfield [0] ['value'] =Bar $ i;
...
node_save($ node);
}

我听说过BatchAPI,但从未使用过。这是解决这个问题的正确的工具吗?该文档谈论超时,但不是内存问题。有没有更简单的东西,我可能会失踪?

解决方案

是的,批量API可以解决这个问题。它会将您的内存使用分解为单独的HTTP请求,每个请求都可以访问您的完整内存限制。


I'm creating about 150 nodes programmatically and running into 'out of memory' errors when doing it all in a single request. (I have a menu callback that generates the nodes and calls node_save() on them.)

Example:

for($i=0; $i<150; $i++) {
    $node = new stdClass(); 
    $node->title="Foo $i";
    $node->field_myfield[0]['value'] = "Bar $i";
    ...
    node_save($node);
}

I've heard of BatchAPI, but never used it. Is that the right tool to get around this? The docs talk about timeouts, but not memory issues. Is there something simpler that I might be missing?

解决方案

Yes, Batch API can solve this problem. It will break up your memory usage into separate HTTP requests, each with access to your full memory limit.

这篇关于如何在drupal中编程生成大量节点时避免“内存不足”错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆