file_get_contents() with context to use http/1.1 significantly slow download speeds

后端 未结 2 1710
栀梦
栀梦 2021-01-12 12:25

Using the code below each image download) file_get_contents() ) takes on average 8-15 seconds.....

If I do not use a context on file_get_contents() then image down

2条回答
  •  攒了一身酷
    2021-01-12 12:56

    Your context tells file_get_contents() to close the HTTP connection every time. Perhaps that is why the code takes so long, as it closes and re-opens connections many times? I am not familiar with the internals of file_get_contents(), but you might be able to tweak the context to use "Connection: keep-alive" for all but the last connection, and "Connection: close" for the last.

提交回复
热议问题