file-get-contents

How to speed up file_get_contents?

…衆ロ難τιáo~ 提交于 2019-12-04 10:22:28
问题 Here's my code: $language = $_GET['soundtype']; $word = $_GET['sound']; $word = urlencode($word); if ($language == 'english') { $url = "<the first url>"; } else if ($language == 'chinese') { $url = "<the second url>"; } $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"User-Agent: <my user agent>" ) ); $context = stream_context_create($opts); $page = file_get_contents($url, false, $context); header('Content-Type: audio/mpeg'); echo $page; But I've found that this runs terribly slow.

Download YouTube video in server

安稳与你 提交于 2019-12-04 10:01:25
问题 I have created a YouTube search engine + download + MP3 convert script. I have used Jeckman's YouTube Downloader for creating this script. Everything is OK, except, I want to download the video into the server instead it downloading it to my computer. I want to do this because, after it gets download, I shall convert the video to MP3 using FFmpeg. Is there any way to get the video downloaded in my server instead of my computer? The download.php contains the following code: <?php // Check

PHP - Content-type not specified assuming application/x-www-form-urlencoded

筅森魡賤 提交于 2019-12-04 09:03:03
问题 For 2 days I'm having trouble with my PHP script on my server. I've changed nothing and suddenly it didn't work anymore. Here is the code: $query = http_build_query($data); $options = array( 'http' => array( 'header' => "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: ".strlen($query)."\r\n", 'method' => "POST", 'content' => $query, ), ); $opts = array('http'=>array('header' => "User-Agent:MyAgent/1.0\r\n",'method' => 'POST', 'content' => http_build_query($data),));

Can't get remote filename to file_get_contents() and then store file

雨燕双飞 提交于 2019-12-04 07:20:47
I want to download a remote file and put it in my server directory with the same name the original has. I tried to use file_get_contents($url) . Problem is that the filename isn't included in $url , it is like: www.domain.com?download=1726 . This URL give me, e.g.: myfile.exe , so I want to use file_put_contents('mydir/myfile.exe'); . How could I retrieve the filename? I tried get_headers() before downloading, but I only have file size, modification date and other information, the filename is missing. I solved it another way. I found that if there is no content-disposition in url headers, then

PHP replace string after using file_get_contents

做~自己de王妃 提交于 2019-12-04 05:22:17
问题 Hi I am looking to replace words in an html email I am loading via file_get_contents Here is my code: <? $message = file_get_contents("http://www.MYwebsiteExample.com/EmailConfirmation.php"); $message = preg_replace('/SAD/', "HAPPY", $message); // Also tried this below and it does not work either $message = str_replace('/SAD/', "HAPPY", $message); ?> I am hoping to find all the patters of SAD (case sensitive) and replace them with HAPPY. For some reason if I use file_get_contents it doesn't

Getting garbage output when scraping a webpage in PHP

浪尽此生 提交于 2019-12-04 04:27:26
问题 I am trying to get the contents of a page from Amazon using file_get_html() but the output comes with weird characters on echo . Can anyone please explain how can I resolve this issue? I also found the following two related questions on Stack Overflow but they did not solve my issue. :) file_get_html() returns garbage Uncompress gzip compressed http response Here is my code: $options = array( 'http'=>array( 'header'=> "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r

HTTP/1.1 505 HTTP Version Not Supported

旧街凉风 提交于 2019-12-04 02:58:59
I'm running a PHP script to grab a web page. It worked fine with many sites, but with one site it fails, returning an error saying "HTTP/1.1 505 HTTP Version Not Supported". This is (part of) my script: for($i = 0; $i < 1; $i++) { $page = file_get_contents("http://www.lovelybooks.de/stoebern/empfehlung/romantic fantasy/?seite=$i"); // do something with $page } Many answers recommend setting the HTTP version explicity. I have tried setting 0.9, 1.0 and 1.1, but it did not change anything. And actually the headers seems to show that the HTTP version requested by my browser and that expected by

How to use PHP to get a webpage into a variable

江枫思渺然 提交于 2019-12-04 02:20:13
问题 I want to download a page from the web, it's allowed to do when you are using a simple browser like Firefox, but when I use "file_get_contents" the server refuses and replies that it understands the command but don't allow such downloads. So what to do? I think I saw in some scripts (on Perl) a way to make your script like a real browser by creating a user agent and cookies, which makes the servers think that your script is a real web browser. Does anyone have an idea about this, how it can

PHP basic auth file_get_contents() [duplicate]

纵然是瞬间 提交于 2019-12-04 02:06:29
This question already has an answer here: Making a HTTP GET request with HTTP-Basic authentication 4 answers I need to parse some XML data from a website. The XML data is in raw format, but before I need to authentificate (basic webserver based auth, with username & password). I tried: $homepage = file_get_contents('http://user:password@IP:PORT/folder/file'); but I get the following error: failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized PHP seems to have problems with the authentification. Any idea how to fix this? You will need to add a stream context to get the extra

faster fopen or file_get_contents?

对着背影说爱祢 提交于 2019-12-04 01:29:06
i am running multiple websites with high traffic , as a requirement , all images are downloaded via image.php?id=IMAGE_ID_HERE . If you ever done that before , you know that that file will be reading the file image and echoing it to the browser with special headers . My problem is , the load on the server is very high (150-200) and TOP command shows multiple instances of image.php , so image.php is running slow ! the problem probably is fopen loading the image to the memory before sending it to the client. How to read a file and pass it through directly? Thank you guys UPDATE After you