header跳转和file_get_contents,哪种速度快些?
header file_get_contents
不管是显示还是下载,就是比较它们的速度。我不会,请叫大家。第一种写法:
header(url地址);
exit();
第二种写法:
echo @file_get_contents(url地址);
exit();
回复讨论(解决方案)
个人认为应该是header更快,看看我的思路:
header() 访问-输出
file_get_contents() 访问-返回数据-输出
这要看:
客户端到目标页
和
服务器到目标页 + 服务器到客户端
哪个快了
个人认为应该是header更快,看看我的思路:
header() 访问-输出
file_get_contents() 访问-返回数据-输出
header() 访问-跳转-输出显示
file_get_contents() 访问-返回时间-输出显示
组长让我测试一下,然后通过数据告诉他,但我迷茫啊......
引用 1 楼 kyzy_yy_pm 的回复:个人认为应该是header更快,看看我的思路:
header() 访问-输出
file_get_contents() 访问-返回数据-输出
header() 访问-跳转-输出显示
file_get_contents() 访问-返回时间-输出显示
组长让我测试一下,然后通过数据告诉他,但我迷茫啊......……
我个人认为,header() 访问- 跳转-输出显示中的跳转可以放到这里考虑吗?因为说的是跳转其实就是访问,我认为应该是这样
这要看:
客户端到目标页
和
客户端到服务器 + 服务器到目标页
哪个快了
我们的这样的,URL对应的文件在A服务器上,网站在B服务器上。
引用 1 楼 kyzy_yy_pm 的回复:个人认为应该是header更快,看看我的思路:
header() 访问-输出
file_get_contents() 访问-返回数据-输出
header() 访问-跳转-输出显示
file_get_contents() 访问-返回时间-输出显示
组长让我测试一下,然后通过数据告诉他,但我迷茫啊......……[
引用 3 楼 xiongmao000738 的回复:引用 1 楼 kyzy_yy_pm 的回复:个人认为应该是header更快,看看我的思路:
header() 访问-输出
file_get_contents() 访问-返回数据-输出
header() 访问-跳转-输出显示
file_get_contents() 访问-返回时间-输出显示
组长让我……
懂你的意思了,刚刚理解错误了。
在服务器上用file_get_contents获取目标页后发送给用户
相当于客户端使用代理访问目标页
至于谁快谁慢,需要实地测试
在服务器上用file_get_contents获取目标页后发送给用户
相当于客户端使用代理访问目标页
至于谁快谁慢,需要实地测试
具体应该怎么测啊?不会啊......
引用 7 楼 xuzuning 的回复:在服务器上用file_get_contents获取目标页后发送给用户
相当于客户端使用代理访问目标页
至于谁快谁慢,需要实地测试
具体应该怎么测啊?不会啊......
每种方式都循环100次看看所用时间哪个大,当然了两种测试要间隔一段时间在测试,不然会出现误差
引用 8 楼 xiongmao000738 的回复:引用 7 楼 xuzuning 的回复:在服务器上用file_get_contents获取目标页后发送给用户
相当于客户端使用代理访问目标页
至于谁快谁慢,需要实地测试
具体应该怎么测啊?不会啊......
每种方式都循环100次看看所用时间哪个大,当然了两种测试要间隔一段时间在测试,不然会出现误差
……
最好是重启机器或者清理内存,不然上次的测试所占用的内存影响下次测试的结果
外在因素太多,首先性质就是不一样一个站内一个站外,header访问考验两次客户端到服务器端的响应时间,file_get_contents 考验客户端到服务器 服务器到源文件服务器两个响应时间,这种东西没法具体判断,只能做分析
这个东西真没测试过,要看需求定吧。
最终是这么测试的。循环500访问同一个地址。ftpstorefile.php里面就是我写的文件下载方法。
$time1 = time() ;
$url = 'http://192.168.84.72:9500/ftpstorefile.php?fileid=73574';
for($i=0; $i $img_file_str = file_get_contents($url);
$time2 = time() ;
var_dump($time2 - $time1);
?>
最终得出来的结果是:header跳转需要20秒左右。file_get_contents大概8秒左右。
可能是因为文件服务器和网站服务器是局域网,所以file_get_contents的速度会快些。
你file_get_contents得到的结果没有输出,所以影响了结果的时间,你应该输出,因为不输出无法得到header类似的结果,这样是不公平的
header跳转 是在服务器端直接转向的吗 还是响应到客户端,客户端进行跳转的
根据我的理解header是 服务器响应客户端时候返回的HTTP报头,告诉客户端跳转到这个地址
也就是客户端访问了两次服务器端。
file_get_contents是服务器端读取文件内容返回,客户端只访问了一次服务器
如果文件是在另一台服务器上的话,就是客户端访问了一次服务器,web服务器访问了一次文件服务器,同样是两次访问,但是我想服务器的速度应该比客户端快吧,包括网速

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.
