PHP 的内部工作原理(非常长的 PHP 脚本)

发布于 2024-10-09 11:00:35 字数 281 浏览 1 评论 0原文

我有一个非常长的 php 脚本,只有 1 页,例如:

mywebsite.com/page.php?id=99999

我有大约 10000-20000 个 id 案例,每个案例都有不同的设置。这会显着减慢我的网站速度吗?

即我的问题实际上是,执行 php 时会发生什么。是服务器执行并显示结果,还是客户端计算机下载、执行并显示结果。

如果是后者,是否意味着加载时间非常慢? 10000-20000 个案例中的每个案例后面都有大约 20-25 行代码。

谢谢,xoxo

I have a really long php script for just 1 page i.e. something like:

mywebsite.com/page.php?id=99999

I have about 10000-20000 cases of the id, each with a different settings. Will this slow down my website significantly?

i.e. my question is really along the lines of, what happens when php is executed. does the server execute it and display the results, or does the client's computer download it, execute it and display the results.

if its the latter, does it mean a really slow load time? each of the 10000-20000 cases has about 20-25 lines of code after it.

thanks, xoxo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剧终人散尽 2024-10-16 11:00:35

PHP 文件通常在 Web 服务器上进行处理(解释),并将输出传递到客户端。

网站速度慢与否,完全取决于 PHP 脚本的实际作用。然而,具有 10000-20000 个 case 的 PHP 文件在代码方面听起来真的非常糟糕。然而,它可能对你的情况表现良好(请原谅双关语)。

一切都取决于实际执行的代码:您只是根据给定的 id 打印出不同的文本还是运行非常昂贵的操作(例如创建 zip 文件、下载内容、计算 PI)到最后一位小数,...)?

A PHP file is usually processed (interpreted) on the web server and the output is passed to the client.

If the website is slow or not, that totally depends on what the PHP script actually does. However, a PHP file with 10000-20000 cases sounds really, really bad code-wise. Yet, it might perform well for your case (pardon the pun).

Everything comes down to what code is actually performed: Do you just print out different text depending on the given id or do you run a really expensive operation (eg. create a zip file, download stuff, compute PI to the last decimal, ...)?

如痴如狂 2024-10-16 11:00:35

10,000 到 20,000 个不同的案例听起来就像一场噩梦。尽管这在技术上是可行的,但我发现很难相信您的处理需求需要这种粒度级别。

10,000 到 20,000 个案例中的每个案例的处理是否真的如此不同,以至于需要完全分开测试和处理?难道没有类似的案例可以用类似的方式处理吗?

例如,如果情况 $x = 5 的处理类似于:

echo 5;

而情况 $x = 10 的处理类似于:

echo 10;

那么这些可以分组为单个测试和单个处理程序:

function dumbEcho($x){
    echo $x;
}

function isDumbEchoAble($x){
    return in_array($x, array(5,10));
}

if (isDumbEchoAble($x)){
   dumbEcho($x);
}

对于每个结构相似的处理集,您可以创建一个 isXXXAble() 函数来测试,并创建一个 XXX() 函数来处理。 [当然,这只是一个简单的例子,旨在演示一个原理、一个概念,不一定是你可以复制/粘贴到当前情况中的代码。]

编程的本质 - 恕我直言 - 就是找到这些结构上的相似之处,找到足以处理独特情况的参数化,然后将此参数化处理应用于这些情况。

10,000 to 20,000 distinct cases sounds like a nightmare. Although it's technically possible, I find it hard to believe that your processing needs require that level of granularity.

Is the processing in each of the 10,000 to 20,000 cases really so different that it needs completely separate testing and handling? Aren't there cases similar enough to be handled in a similar way?

For example, if the processing for case $x = 5 is something like:

echo 5;

And the processing for case $x = 10 is something like:

echo 10;

Then these could be grouped into a single test and single handler:

function dumbEcho($x){
    echo $x;
}

function isDumbEchoAble($x){
    return in_array($x, array(5,10));
}

if (isDumbEchoAble($x)){
   dumbEcho($x);
}

For each structurally similar set of processing, you could create a isXXXAble() function to test and an XXX() function to process. [Of course, this is just a simple example, intended to demonstrate a principle, a concept, not necessarily code that you can copy/paste into your current situation.]

The essence of programming - IMHO - is to find these structural similarities, find a parameterization sufficient to handle the unique cases, and then apply this paramaterized processing to those cases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文