471,306 Members | 884 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

problem with file()

vKp
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

....failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).

Jul 17 '05 #1
9 4147
vKp wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).


Use error suppressing and error checking :-)

<?php
$url = 'http://www.example.com/find?one,two';
$x = @file($url); // @ for error suppressing
if ($x === false) {
// error checking, maybe
die('Invalid URL');
} // else continue
?>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
vKp
Pedro Graca wrote:
vKp wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).

Use error suppressing and error checking :-)

<?php
$url = 'http://www.example.com/find?one,two';
$x = @file($url); // @ for error suppressing
if ($x === false) {
// error checking, maybe
die('Invalid URL');
} // else continue
?>

I think that I wasn't very clear. Surpressing the error won't help,
because I need it to open the url. It IS a valid url. I've accessed it
via IE and gecko based browsers. What I really need to know is why PHP
won't open it.

Thanks for your reply though :)

Jul 17 '05 #3
On Wed, 21 Jan 2004 21:37:19 +0000, vKp <as*****@hotmail.com> wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).


PHP version? allow_url_fopen enabled? http listed in the Registered PHP
Streams section of phpinfo()? Minimal example code demonstrating problem?

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #4
vKp wrote:

Pedro Graca wrote:
vKp wrote:
I'm having a problem with file(). If I try to open a url of the form
"http://example.com/find?one,two", I get an error of the following form:

...failed to create stream: Bad file descriptor...

What's going wrong? How can I make this work? (Note that I have no
control over the form of the remote urls).

Use error suppressing and error checking :-)

<?php
$url = 'http://www.example.com/find?one,two';
$x = @file($url); // @ for error suppressing
if ($x === false) {
// error checking, maybe
die('Invalid URL');
} // else continue
?>

I think that I wasn't very clear. Surpressing the error won't help,
because I need it to open the url. It IS a valid url. I've accessed it
via IE and gecko based browsers. What I really need to know is why PHP
won't open it.


Without the real url, it's hard to say, but you might try url_encode()ing it.
IE will take and convert some invalid URL characters (ie. spaces). So opening a
link in IE is not a good test of a URL's validity.

If that's not your problem, I'd try all of Andy's suggestions, then
fsockopen(). I had some trouble at one point trying to open a webpage. It
turned out that you had to set a USER_AGENT to view the webpage (it was an
anti-spambot feature of fark.com). I never would have figured that out because
the link always came up fine in IE and NS.

Regards,
Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

I have a spam filter. Please include "PHP" in the
subject line to ensure I'll get your message.
Jul 17 '05 #5
vKp
Andy Hassall wrote:

PHP version? allow_url_fopen enabled? http listed in the Registered PHP
Streams section of phpinfo()? Minimal example code demonstrating problem?


4.3.1 (Can't upgrade), allow_url_fopen is on, and http is listed.
The exact code that causes the problem is:

$Name = "Buscemi,Steve";
$Name = urlencode($Name); //fails with or without urlencoding
$BaseURL = "http://us.imdb.com/Name?" . $Name;

$URL = join ("", file($BaseURL));
echo $URL;

This results in:
Warning: file(http://us.imdb.com/Name?Buscemi%2CSteve) [function.file]:
failed to create stream: Bad file descriptor in [... file name at the
join line...]

I really can't understand what's going on.

Jul 17 '05 #6
On Wed, 21 Jan 2004 23:33:39 +0000, vKp wrote:

I think that I wasn't very clear. Surpressing the error won't help,
because I need it to open the url. It IS a valid url. I've accessed it
via IE and gecko based browsers. What I really need to know is why PHP
won't open it.

Could it be that your host has blocked outbound port 80 from the server?
Or perhaps the remote site has blocked your server's IP address?

Try telnetting to the remote server (port 80) and doing something like

GET /file?value=x&variable=y HTTP/1.0

(that's two carriage returns, btw)

And see what comes back, in case it isn't quite so valid a URL as you
thought.
One thing that people sometimes miss is that you need to put a / at the
end of directories -

For example:

http://something.org/hello

points to a file called hello

and

http://something.org/hello/

points to a directory called hello, and will probably return a file called
something along the lines of index.php or default.asp (depending on the
server and configuration), or a directory listing, or a directory listing
denied message.

HTH,

AdamT
Jul 17 '05 #7
vKp <as*****@hotmail.com> wrote:
This results in:
Warning: file(http://us.imdb.com/Name?Buscemi%2CSteve) [function.file]:
failed to create stream: Bad file descriptor in [... file name at the
join line...]

I really can't understand what's going on.


The url above will result in a redirect:

GET /Name?Buscemi%2CSteve HTTP/1.1
Host: us.imdb.com
[snip]

HTTP/1.1 302 Found
Date: Thu, 22 Jan 2004 17:44:14 GMT
Server: Apache
Location: /find?q=Buscemi,Steve;nm=1
[snip]

maybe you are experiencing a bug? But it works for me on 4.1.2....

--

Daniel Tryba

Jul 17 '05 #8
On Thu, 22 Jan 2004 16:24:10 +0000, vKp <as*****@hotmail.com> wrote:
Andy Hassall wrote:

PHP version? allow_url_fopen enabled? http listed in the Registered PHP
Streams section of phpinfo()? Minimal example code demonstrating problem?


4.3.1 (Can't upgrade), allow_url_fopen is on, and http is listed.
The exact code that causes the problem is:

$Name = "Buscemi,Steve";
$Name = urlencode($Name); //fails with or without urlencoding
$BaseURL = "http://us.imdb.com/Name?" . $Name;

$URL = join ("", file($BaseURL));
echo $URL;

This results in:
Warning: file(http://us.imdb.com/Name?Buscemi%2CSteve) [function.file]:
failed to create stream: Bad file descriptor in [... file name at the
join line...]

I really can't understand what's going on.


Works for me, PHP 4.3.4. Search on bugs.php.net, there seem to be a few
reports of similar things, fixed in various versions and re-emerging again in
others.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #9
vKp
Andy Hassall wrote:


Works for me, PHP 4.3.4. Search on bugs.php.net, there seem to be a few
reports of similar things, fixed in various versions and re-emerging again in
others.


Thanks for the help. It appears to be a bug. I tried the same code on
servers running 4.1.1 and 4.3.4, and it worked fine. So just need to
upgrade my local server (hopefully).

Thanks.

Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Keith Dewell | last post: by
15 posts views Thread by Ken Allen | last post: by
5 posts views Thread by IkBenHet | last post: by
13 posts views Thread by Lee Newson | last post: by
2 posts views Thread by key9 | last post: by
4 posts views Thread by Salad | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.