473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 4328
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
2
by: key9 | last post by:
Hi all on last post I confused on how to organize file of class, ok ,the problem solved : should include class define head on cpp file. but this time ,still link error: strange is I put the...
0
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual...
4
by: Salad | last post by:
I have a situation where some, not all, users get the message "Couldn't find file "F:\AccessApps\AppName.mdw". This file is required for startup". My app the users are attempting to access is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.