创建很多DOM元素。哪种方法更快?回应HTML或使用PHP DOM类? [英] Creating a lot of DOM elements. which method is faster? Echoing the HTML or using PHP DOM class?

查看:116
本文介绍了创建很多DOM元素。哪种方法更快?回应HTML或使用PHP DOM类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户访问我的网站时,我需要创建约10k个元素,其类似于< ul> li>



创建HTML的过程当前需要大约15秒钟,我创建一个数组中的HTML然后json_encode并回显。



我正在努力缩短流程。我的问题是:



使用php的 DOM 类来创建元素。



或只是创建HTML并回显它?

解决方案

15秒创建和json_encode 10K元素..这是不对的。瓶颈无疑在这里不是PHP。数据来自哪里?在单个查询或嵌入式查询中循环?可以缓存数据吗?如果是这样,请执行此操作。



您需要在进行优化之前进行正确的基准测试,您现在要做的是修剪毫秒数,这将需要15秒的时间。 p>

I need to create about 10k elements when a user visit my site, its sort of a big tree like <ul> and <li>.

The process of creating the HTML currently takes about 15 seconds, i create the HTML in an array then json_encode and echo it.

i am trying to shorten the process. my question is:

would it be faster to use php's DOM class to create the elements.

or just create the HTML and echo it?

解决方案

15 seconds to create and json_encode 10K elements .. this can't be right. The bottle neck is undoubtedly not PHP here. Where is that data coming from, a database ? In a single query or embedded queries in a loop ? Can the data be cached ? If so, do so.

You need to properly benchmark before optimizing, what you're trying to do now is trim milliseconds off an operation that takes 15 seconds.

这篇关于创建很多DOM元素。哪种方法更快?回应HTML或使用PHP DOM类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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