压缩 - 如果以及如何 [英] Compression - if and how

查看:54
本文介绍了压缩 - 如果以及如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个生成XML文件的脚本,这些文件通过new SimpleXMLElement($ sUrl)请求发送到客户端应用程序

,0,真)。客户端和

服务器都运行PHP 5.2,XML文件可以大到150 KB。

(客户端然后使用XML中的数据生成HTML页面文件

并将其发送到浏览器。因此涉及3方:用户

请求HTML页面 - 服务器请求来自其他服务器的XML数据 - 其他

服务器发回XML数据 - 第一个服务器从它生成HTML页面

并将其发送给客户端。这里我关注两台服务器之间的通信

。)


现在150 KB在通过互联网传输时看起来相当大,所以我认为压缩XML文件可能是个好主意(应该是收缩

降至10%左右)。另一方面:压缩和解压缩也使用了
资源,我假设从一个服务器转移到另一个服务器

无论如何通过宽带连接发生,所以也许它''是不是真的值得b $ b压缩数据的麻烦?


但是如果确实建议使用压缩,那就是

最好还是最优雅的方式呢?我可以告诉SimpleXMLElement

构造函数发送适当的头来接受压缩吗?然后

会自动解压缩吗?并使用一些

output_handler函数在

发送之前自动压缩数据?或者我应该明确地调用所有(de)压缩

函数?因为似乎有几个选项(zlib,gz,

....) - 我应该选择哪一个?


有什么建议吗?


问候,

托马斯

-

Ce n''est pas parce qu''ils sontnombreuxàavoirtort qu''ils ont raison!

(Coluche)

Hello,

I have a script that generates XML files which are sent to a client app
on request via "new SimpleXMLElement( $sUrl, 0, true )". Both client and
server run PHP 5.2 and the XML file can get as large as about 150 KB.
(The client then generates an HTML page using the data in the XML file
and sends it to the browser. So there are 3 parties involved: User
requests HTML page - server requests XML data from other server - other
server sends back XML data - first server generates HTML page from it
and sends it to the client. Here I am concerned about the communication
between the two servers.)

Now 150 KB seem quite big when transferred over the internet, so I
thought it might be a good idea to compress the XML file (should shrink
down to about 10%). On the other hand: compression and decompression use
resources as well and I assume the transfer from one server to another
happens over a broadband connection anyway, so maybe it''s not really
worth the trouble to compress the data?

But if it is indeed advisable to use compression, which would be the
best or most elegant way to go about it? Can I tell the SimpleXMLElement
constructor to send the appropriate headers to accept compression? And
will the decompression then happen automatically? And use some
output_handler function to have the data compressed automatically before
sending it out? Or should I rather call all the (de)compressing
functions explicitly? And as there seem to be several options (zlib, gz,
....) - which one should I choose?

Any advice?

Greetings,
Thomas
--
Ce n''est pas parce qu''ils sont nombreux à avoir tort qu''ils ont raison!
(Coluche)

推荐答案

sUrl,0,true) " ;.客户端和

服务器都运行PHP 5.2,XML文件可以大到150 KB。

(客户端然后使用XML中的数据生成HTML页面文件

并将其发送到浏览器。因此涉及3方:用户

请求HTML页面 - 服务器请求来自其他服务器的XML数据 - 其他

服务器发回XML数据 - 第一个服务器从它生成HTML页面

并将其发送给客户端。这里我关注两台服务器之间的通信

。)


现在150 KB在通过互联网传输时看起来相当大,所以我认为压缩XML文件可能是个好主意(应该是收缩

降至10%左右)。另一方面:压缩和解压缩也使用了
资源,我假设从一个服务器转移到另一个服务器

无论如何通过宽带连接发生,所以也许它''是不是真的值得b $ b压缩数据的麻烦?


但是如果确实建议使用压缩,那就是

最好还是最优雅的方式呢?我可以告诉SimpleXMLElement

构造函数发送适当的头来接受压缩吗?然后

会自动解压缩吗?并使用一些

output_handler函数在

发送之前自动压缩数据?或者我应该明确地调用所有(de)压缩

函数?因为似乎有几个选项(zlib,gz,

....) - 我应该选择哪一个?


有什么建议吗?


问候,

托马斯

-

Ce n''est pas parce qu''ils sontnombreuxàavoirtort qu''ils ont raison!

(Coluche)
sUrl, 0, true )". Both client and
server run PHP 5.2 and the XML file can get as large as about 150 KB.
(The client then generates an HTML page using the data in the XML file
and sends it to the browser. So there are 3 parties involved: User
requests HTML page - server requests XML data from other server - other
server sends back XML data - first server generates HTML page from it
and sends it to the client. Here I am concerned about the communication
between the two servers.)

Now 150 KB seem quite big when transferred over the internet, so I
thought it might be a good idea to compress the XML file (should shrink
down to about 10%). On the other hand: compression and decompression use
resources as well and I assume the transfer from one server to another
happens over a broadband connection anyway, so maybe it''s not really
worth the trouble to compress the data?

But if it is indeed advisable to use compression, which would be the
best or most elegant way to go about it? Can I tell the SimpleXMLElement
constructor to send the appropriate headers to accept compression? And
will the decompression then happen automatically? And use some
output_handler function to have the data compressed automatically before
sending it out? Or should I rather call all the (de)compressing
functions explicitly? And as there seem to be several options (zlib, gz,
....) - which one should I choose?

Any advice?

Greetings,
Thomas
--
Ce n''est pas parce qu''ils sont nombreux à avoir tort qu''ils ont raison!
(Coluche)


我不会为此烦恼,除非这是一个显着的瓶颈和

正在影响用户体验。


但是,如果你确实认为你需要压缩,你可以

通过使用mod_gzip,

zlib.output_compression或ob_gzhandler使用gzip对服务器的响应进行编码来实现。然后使用gzip作为CURLOPT_ENCODING值,使用cURL

下载。增加的CPU可以忽略不计

大多数情况下。


问候,


John Peters


8月8日下午4:11,Thomas Mlynarczyk< tho ... @ mlynarczyk-webdesign.de>

写道:
I wouldn''t bother with it unless this is a significant bottleneck and
is impacting the user experience.

However, if you do think you need compression at some point, you can
do it by encoding the server''s response with gzip using mod_gzip,
zlib.output_compression, or ob_gzhandler. Then download with cURL
using gzip as the CURLOPT_ENCODING value. The added CPU is negligible
in most cases.

Regards,

John Peters

On Aug 8, 4:11 pm, Thomas Mlynarczyk <tho...@mlynarczyk-webdesign.de>
wrote:

您好,


我有一个生成XML文件的脚本,这些文件会根据请求发送到客户端应用程序

SimpleXMLElement(
Hello,

I have a script that generates XML files which are sent to a client app
on request via "new SimpleXMLElement(


sUrl,0,true)"。客户端和

服务器都运行PHP 5.2,XML文件可以大到150 KB。

(客户端然后使用XML中的数据生成HTML页面文件

并将其发送到浏览器。因此涉及3方:用户

请求HTML页面 - 服务器请求来自其他服务器的XML数据 - 其他

服务器发回XML数据 - 第一个服务器从它生成HTML页面

并将其发送给客户端。这里我关注两台服务器之间的通信

。)


现在150 KB在通过互联网传输时看起来相当大,所以我认为压缩XML文件可能是个好主意(应该是收缩

降至10%左右)。另一方面:压缩和解压缩也使用了
资源,我假设从一个服务器转移到另一个服务器

无论如何通过宽带连接发生,所以也许它''是不是真的值得b $ b压缩数据的麻烦?


但是如果确实建议使用压缩,那就是

最好还是最优雅的方式呢?我可以告诉SimpleXMLElement

构造函数发送适当的头来接受压缩吗?然后

会自动解压缩吗?并使用一些

output_handler函数在

发送之前自动压缩数据?或者我应该明确地调用所有(de)压缩

函数?因为似乎有几个选项(zlib,gz,

......) - 我应该选择哪一个?


有什么建议吗?

问候,

托马斯


-

Ce n''est pas parce qu ''sils nontnombreuxàavoirtort qu''ils ont raison!

(Coluche)
sUrl, 0, true )". Both client and
server run PHP 5.2 and the XML file can get as large as about 150 KB.
(The client then generates an HTML page using the data in the XML file
and sends it to the browser. So there are 3 parties involved: User
requests HTML page - server requests XML data from other server - other
server sends back XML data - first server generates HTML page from it
and sends it to the client. Here I am concerned about the communication
between the two servers.)

Now 150 KB seem quite big when transferred over the internet, so I
thought it might be a good idea to compress the XML file (should shrink
down to about 10%). On the other hand: compression and decompression use
resources as well and I assume the transfer from one server to another
happens over a broadband connection anyway, so maybe it''s not really
worth the trouble to compress the data?

But if it is indeed advisable to use compression, which would be the
best or most elegant way to go about it? Can I tell the SimpleXMLElement
constructor to send the appropriate headers to accept compression? And
will the decompression then happen automatically? And use some
output_handler function to have the data compressed automatically before
sending it out? Or should I rather call all the (de)compressing
functions explicitly? And as there seem to be several options (zlib, gz,
...) - which one should I choose?

Any advice?

Greetings,
Thomas

--
Ce n''est pas parce qu''ils sont nombreux à avoir tort qu''ils ont raison!
(Coluche)


这篇关于压缩 - 如果以及如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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