[PHP] Re: fopen never ends?

2008-02-19 Thread Nathan Rixham

Paul van Brouwershaven wrote:

When you run the folling script, it will never ends?

I have seen this more then once, I know that there is no service running 
at the target host, but why is the script not printing the failed message?


It's only with a few ip-number I have this problem.

if ($fp = fopen('https://81.23.227.9', 'rb', false)) {
echo ok;
} else {
echo failed;
}

Best Regards,

Paul van Brouwershaven


I don't think this is a php problem, just load the url up in a browser 
and you'll see the same, appears to be a misconfigured server at the 
otherside - probably confused about not being passed a name based host 
header in the request.


Perhaps concider moving to fsockopen or stream_socket_client with 
timeout parameters to solve your issue.


Many Regard

Nathan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen never ends?

2008-02-19 Thread Paul van Brouwershaven

Nathan Rixham wrote:
I don't think this is a php problem, just load the url up in a browser 
and you'll see the same, appears to be a misconfigured server at the 
otherside - probably confused about not being passed a name based host 
header in the request.
I know that my browser is also waiting a long time, but strange that there is no timeout in fopen? 
My scripts are getting stuck and eventually they will hang my server. (when I start a new job every 
x minutes)


Perhaps concider moving to fsockopen or stream_socket_client with 
timeout parameters to solve your issue.


fsockopen has no context and with stream_socket_client I have no timeout but 
stream_context_get_options is not returning the right data


$options = stream_context_get_options($fp);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen never ends?

2008-02-19 Thread Chris


Perhaps concider moving to fsockopen or stream_socket_client with 
timeout parameters to solve your issue.


fsockopen has no context


Maybe I'm missing something but it returns a resource just like fopen.

http://php.net/fsockopen

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen never ends?

2008-02-19 Thread Richard Lynch
On Tue, February 19, 2008 5:49 pm, Chris wrote:

 Perhaps concider moving to fsockopen or stream_socket_client with
 timeout parameters to solve your issue.

 fsockopen has no context

 Maybe I'm missing something but it returns a resource just like fopen.

 http://php.net/fsockopen

And you can control its timeout for OPENING with an ini_set of that
one timeout setting.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen never ends?

2008-02-19 Thread Jim Lucas

Paul van Brouwershaven wrote:

Nathan Rixham wrote:
I don't think this is a php problem, just load the url up in a browser 
and you'll see the same, appears to be a misconfigured server at the 
otherside - probably confused about not being passed a name based 
host header in the request.
I know that my browser is also waiting a long time, but strange that 
there is no timeout in fopen? My scripts are getting stuck and 
eventually they will hang my server. (when I start a new job every x 
minutes)


Perhaps concider moving to fsockopen or stream_socket_client with 
timeout parameters to solve your issue.


fsockopen has no context and with stream_socket_client I have no timeout 
but stream_context_get_options is not returning the right data


$options = stream_context_get_options($fp);




Check out the first Note: section on this page.

http://us3.php.net/manual/en/function.stream-socket-client.php

First thing it tells you is that you can set a timeout for the 
connection using stream_set_timeout().


I know this can be done.  I am running a PHP daemon that that acts as 
both a server and a client.


Jim Lucas

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen never ends?

2008-02-19 Thread Paul van Brouwershaven
The timeout is not the problem, the probleem is I'm not getting the ssl (like the peer cert) info 
into the stream_context_get_options


Jim Lucas wrote:

Paul van Brouwershaven wrote:

Nathan Rixham wrote:
I don't think this is a php problem, just load the url up in a 
browser and you'll see the same, appears to be a misconfigured server 
at the otherside - probably confused about not being passed a name 
based host header in the request.
I know that my browser is also waiting a long time, but strange that 
there is no timeout in fopen? My scripts are getting stuck and 
eventually they will hang my server. (when I start a new job every x 
minutes)


Perhaps concider moving to fsockopen or stream_socket_client with 
timeout parameters to solve your issue.


fsockopen has no context and with stream_socket_client I have no 
timeout but stream_context_get_options is not returning the right data


$options = stream_context_get_options($fp);




Check out the first Note: section on this page.

http://us3.php.net/manual/en/function.stream-socket-client.php

First thing it tells you is that you can set a timeout for the 
connection using stream_set_timeout().


I know this can be done.  I am running a PHP daemon that that acts as 
both a server and a client.


Jim Lucas



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-30 Thread Richard Lynch
DNS records are failing to lookup the domain name for you...

Maybe just put the URL back into a queue to try later.

You should also toy with nslookup or dig from the command line and see
if you can get it to fail as often.

On Thu, December 27, 2007 12:00 pm, Albert Wiersch wrote:

 Some additional info. It seems I am getting these warnings when it
 fails:

 Warning: fopen() [function.fopen]: php_network_getaddresses:
 getaddrinfo
 failed: Name or service not known

 Warning: fopen(http://wanganda2u.co.uk) [function.fopen]: failed to
 open
 stream:

 Now I have to find out why that is failing some of the time but not
 other
 times.

 --
 Albert Wiersch
 Fix your website: http://onlinewebcheck.com


 Albert Wiersch [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]

 I noticed my script at http://onlinewebcheck.com was sometimes
 (fairly
 often) failing to open some URLs that users have entered. fopen()
 returns
 false very quickly, but when tried again with the same URL,
 sometimes it
 works. What would cause this behavior? Why does fopen() occasionally
 fail
 to open valid http addresses but works at other times?

 --
 Albert Wiersch

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-30 Thread Richard Lynch
If it's a busy server, you may be running out of TCP connections...

If PHP can't open ANY connection at all, it can't do a DNS lookup, and
it would fail very fast, as it's hitting an OS limit/cap on the number
of connections and not even getting to try to talk to the Internet.

On Fri, December 28, 2007 12:03 pm, Albert Wiersch wrote:
 I'm now using PHP 5.2.5.

 Well, it seems to still be happening. This describes the problem but I
 haven't found a solution that works for me yet:
 http://bugs.php.net/bug.php?id=11058

 Is it a PHP problem or DNS? It works sometimes but not other
 times..
 something strange is going on.

 Example messages:
 [Fri Dec 28 11:59:04 2007] [error] [client 192.168.0.51] PHP Warning:
 fopen() [a href='function.fopen'function.fopen/a]:
 php_network_getaddresses: getaddrinfo failed: Name or service not
 known
 [Fri Dec 28 11:59:04 2007] [error] [client 192.168.0.51] PHP Warning:
 fopen(http://www.lantanalinks.com) [a
 href='function.fopen'function.fopen/a]: failed to open stream:
 Success

 I suppose I could adjust the script to try again if it fails the first
 time,
 but I shouldn't have to.

 Some additional info, when it fails with this problem, it fails very
 quickly
 (in less than half a second)... its like it doesn't even try to look
 up the
 name.

 --
 Albert Wiersch
 Fix your website: http://onlinewebcheck.com


 Albert Wiersch [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]

 I noticed my script at http://onlinewebcheck.com was sometimes
 (fairly
 often) failing to open some URLs that users have entered. fopen()
 returns
 false very quickly, but when tried again with the same URL,
 sometimes it
 works. What would cause this behavior? Why does fopen() occasionally
 fail
 to open valid http addresses but works at other times?

 --
 Albert Wiersch

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-29 Thread Albert Wiersch

Dan [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 You really need to filter your input more, have a list of what is 
 acceptable not what is unacceptable.  That being, make it a requirement 
 that the url input has a TDL(.com, .net, .org, etc.) or is a valid IP(ping 
 it), only allow alphanumerics for the name, etc.  When you don't validate 
 your site can get hacked, I know it's not really insecure but it's just an 
 example of input you may not expect, if you try to validate 
 http://localhost it goes ahead and validates your server's html.

I make sure it starts with http: or https: and change spaces to %20 so 
it will work. I also check for some possible recursion issues. I think I'm 
fairly secure just doing that. What could happen security wise? What else do 
you think I need to do? I don't want to check for a TLD as there are many 
and I don't think it is necessary... and pinging doesn't seem like a good 
idea either as some servers probably won't respond to pings.

The localhost issue is interesting, but I don't see it as a security issue.

I would like to know if there are any serious secirity issues I may be 
overlooking though.

Thanks,
Albert

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-28 Thread Albert Wiersch
I'm now using PHP 5.2.5.

Well, it seems to still be happening. This describes the problem but I 
haven't found a solution that works for me yet:
http://bugs.php.net/bug.php?id=11058

Is it a PHP problem or DNS? It works sometimes but not other times.. 
something strange is going on.

Example messages:
[Fri Dec 28 11:59:04 2007] [error] [client 192.168.0.51] PHP Warning: 
fopen() [a href='function.fopen'function.fopen/a]: 
php_network_getaddresses: getaddrinfo failed: Name or service not known
[Fri Dec 28 11:59:04 2007] [error] [client 192.168.0.51] PHP Warning: 
fopen(http://www.lantanalinks.com) [a 
href='function.fopen'function.fopen/a]: failed to open stream: Success

I suppose I could adjust the script to try again if it fails the first time, 
but I shouldn't have to.

Some additional info, when it fails with this problem, it fails very quickly 
(in less than half a second)... its like it doesn't even try to look up the 
name.

-- 
Albert Wiersch
Fix your website: http://onlinewebcheck.com


Albert Wiersch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 I noticed my script at http://onlinewebcheck.com was sometimes (fairly 
 often) failing to open some URLs that users have entered. fopen() returns 
 false very quickly, but when tried again with the same URL, sometimes it 
 works. What would cause this behavior? Why does fopen() occasionally fail 
 to open valid http addresses but works at other times?

 -- 
 Albert Wiersch 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-28 Thread Wolf
DNS issues

Albert Wiersch wrote:
 I'm now using PHP 5.2.5.
 
 Well, it seems to still be happening. This describes the problem but I 
 haven't found a solution that works for me yet:
 http://bugs.php.net/bug.php?id=11058
 
 Is it a PHP problem or DNS? It works sometimes but not other times.. 
 something strange is going on.
 
 Example messages:
 [Fri Dec 28 11:59:04 2007] [error] [client 192.168.0.51] PHP Warning: 
 fopen() [a href='function.fopen'function.fopen/a]: 
 php_network_getaddresses: getaddrinfo failed: Name or service not known
 [Fri Dec 28 11:59:04 2007] [error] [client 192.168.0.51] PHP Warning: 
 fopen(http://www.lantanalinks.com) [a 
 href='function.fopen'function.fopen/a]: failed to open stream: Success
 
 I suppose I could adjust the script to try again if it fails the first time, 
 but I shouldn't have to.
 
 Some additional info, when it fails with this problem, it fails very quickly 
 (in less than half a second)... its like it doesn't even try to look up the 
 name.
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-28 Thread Albert Wiersch

Wolf [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 DNS issues

I think I've solved this. I found a problem with resolv.conf that contained 
some outdated DNS servers. After changing that and rebooting the server it 
seems to be working. It didn't seem to work after just changing the file and 
restarting apache though, it seems like the reboot was necessary. I don't 
know why but so far do good.

The root.hints file was also updated. I'm not sure if that had anything to 
do with it but it was updated in the process of trying to fix the problem.

Albert 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-28 Thread Dan
Albert Wiersch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]


I noticed my script at http://onlinewebcheck.com was sometimes (fairly 
often) failing to open some URLs that users have entered. fopen() returns 
false very quickly, but when tried again with the same URL, sometimes it 
works. What would cause this behavior? Why does fopen() occasionally fail 
to open valid http addresses but works at other times?


--
Albert Wiersch


You really need to filter your input more, have a list of what is acceptable 
not what is unacceptable.  That being, make it a requirement that the url 
input has a TDL(.com, .net, .org, etc.) or is a valid IP(ping it), only 
allow alphanumerics for the name, etc.  When you don't validate your site 
can get hacked, I know it's not really insecure but it's just an example of 
input you may not expect, if you try to validate http://localhost it goes 
ahead and validates your server's html.


- Dan 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-27 Thread Albert Wiersch

Some additional info. It seems I am getting these warnings when it fails:

Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo 
failed: Name or service not known

Warning: fopen(http://wanganda2u.co.uk) [function.fopen]: failed to open 
stream:

Now I have to find out why that is failing some of the time but not other 
times.

-- 
Albert Wiersch
Fix your website: http://onlinewebcheck.com


Albert Wiersch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 I noticed my script at http://onlinewebcheck.com was sometimes (fairly 
 often) failing to open some URLs that users have entered. fopen() returns 
 false very quickly, but when tried again with the same URL, sometimes it 
 works. What would cause this behavior? Why does fopen() occasionally fail 
 to open valid http addresses but works at other times?

 -- 
 Albert Wiersch 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-27 Thread Daniel Brown
On Dec 27, 2007 1:00 PM, Albert Wiersch [EMAIL PROTECTED] wrote:

 Some additional info. It seems I am getting these warnings when it fails:

 Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo
 failed: Name or service not known

That sounds like a DNS resolution error.  If you have Telnet/SSH
or local console access, try doing a dig, traceroute, and ping series
on it.

-- 
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-27 Thread Albert Wiersch

Daniel Brown [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

That sounds like a DNS resolution error.  If you have Telnet/SSH
 or local console access, try doing a dig, traceroute, and ping series
 on it.

Hi Daniel,

Yes, I have SSH access. I will keep that in mind. Upgrading to 5.2.5 may 
have addressed this issue though. If not, then I'll concentrate on a 
possible DNS resolution problem.

Albert

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen() for http:// sometimes working, sometimes not

2007-12-27 Thread Albert Wiersch

Albert Wiersch [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

 Yes, I have SSH access. I will keep that in mind. Upgrading to 5.2.5 may 
 have addressed this issue though. If not, then I'll concentrate on a 
 possible DNS resolution problem.

Well, it seems to still be happening. This describes the problem but I 
haven't found a solution that works for me yet:
http://bugs.php.net/bug.php?id=11058

Is it a PHP problem or DNS? It works sometimes but not other times.. 
something strange is going on.

Albert

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen: space character in filename

2006-07-28 Thread Jo�o C�ndido de Souza Neto
Did you read this?

http://br.php.net/manual/en/function.fopen.php

Christian Calloway [EMAIL PROTECTED] escreveu na mensagem 
news:[EMAIL PROTECTED]
 Hello all,

 this seems like an easy question, but I could sure as hell couldn't find 
 any responces to it through initial searched. I am running php on an XP 
 system and I need to open a file contained with a set of directories which 
 may or may not have a space character; so for example:

 fopen (X:\Dont Talk\About\My Momma\please.txt, x);

 I tried using \ characters, no luck (even attempted to cancel out the 
 backspace characters ala \\ and http space code %20, and still nothing.) 
 Any ideas? 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen failing, permission denied

2006-03-01 Thread Dan Baker
Chris [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Dan Baker wrote:
 I have the following code snippet:
 $h = fopen($path/file.txt, 'x+');

 And it generates the following error:
 Warning: fopen(/home/./myarea/file.txt): failed to open stream: 
 Permission denied

 The path is correct, but the php process doesn't seem to have file 
 permissions in the folder.
 Is there some magic I can do to allow php to have file rights to the 
 myarea folder?  (This is on a purchased ISP site)

 Go in through ftp or ssh and fix the permissions.

 If you only want to read the file, then it only needs to be 644.

 If you need to write the file it will either need to be 646 or 664.

 That's your only option apart from deleting the file (through ftp) and 
 recreating it through your php script ... or getting your host to change 
 to the CGI version of php which is most unlikely to happen.

I'm actually trying to create the file (thus the 'x+' mode).  The file 
doesn't exists.  It appears to me that the php process doesn't have 
permission to the entire folder.  My ftp client has full access to the 
folder (myarea), but the php process doesn't.  The folder is under the 
http folder.  I'll check if I can alter the permissions on the myarea 
folder.

DanB

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen failing, permission denied

2006-03-01 Thread Dan Baker
(SOLVED, see below)

Dan Baker [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Chris [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 Dan Baker wrote:
 I have the following code snippet:
 $h = fopen($path/file.txt, 'x+');

 And it generates the following error:
 Warning: fopen(/home/./myarea/file.txt): failed to open stream: 
 Permission denied

 The path is correct, but the php process doesn't seem to have file 
 permissions in the folder.
 Is there some magic I can do to allow php to have file rights to the 
 myarea folder?  (This is on a purchased ISP site)

 Go in through ftp or ssh and fix the permissions.

 If you only want to read the file, then it only needs to be 644.

 If you need to write the file it will either need to be 646 or 664.

 That's your only option apart from deleting the file (through ftp) and 
 recreating it through your php script ... or getting your host to change 
 to the CGI version of php which is most unlikely to happen.

 I'm actually trying to create the file (thus the 'x+' mode).  The file 
 doesn't exists.  It appears to me that the php process doesn't have 
 permission to the entire folder.  My ftp client has full access to the 
 folder (myarea), but the php process doesn't.  The folder is under the 
 http folder.  I'll check if I can alter the permissions on the myarea 
 folder.

I took the suggestion from Chris, and checked the permissions on the 
myarea folder.  They were set so others could NOT write.  I added this 
permission, and everything works great now!

Thanks for the pointer Chris

DanB


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen

2005-10-26 Thread Petr Smith

Hi,

yes, there could be some problem with your code. But it depends on what 
are you trying to archieve.


If you are trying to put whole file to database, there is no reason to 
use fgets function. Just use $buffer=file_get_contents($filename); and 
put the buffer into SQL. No reason to read it line by line using fgets. 
The whole file will end in memory in the SQL section, so it doesn't 
matter ho you read it.


If you want to process huge file line by line, it's really good idea to 
not put whole file to memory (using file_get_contents) but to read it 
line by line using fgets, process every line and forgot it. The file 
could be very large and you still need only very small memory amount. 
And there can be problem you are saying.


What if there is some line longer than 4096 bytes (or some bigger 
limit)?? You can solve it simply using code like this:


$dataFile = fopen( $filename, r ) ;
$buffer = ;
while (!feof($dataFile)) {
$buffer .= fgets($dataFile, 4096);
if (strstr($buffer, \n) === false  !feof($dataFile)) {
// long line
continue;
}   
echo $buffer;
$buffer = ;
}

Petr

John Taylor-Johnston wrote:
It does what I want, but I worry 4096 may not be big enough. Possible? 
Is there a way to detect the filesize and insert a value for 4096?

$buffer = fgets($dataFile, $filesize);
Is this what it is for?
John


?php
#http://ca3.php.net/fopen
$filename = /var/www/html2/assets/about.htm ;
$dataFile = fopen( $filename, r ) ;
  while (!feof($dataFile))
  {
  $buffer = fgets($dataFile, 4096);
  echo $buffer;
  }
$sql = insert into table ... $buffer;
?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen for http://

2005-05-27 Thread Peter Brodersen
On Fri, 27 May 2005 13:57:12 -0500, in php.general [EMAIL PROTECTED]
(Jay Paulson) wrote:

For example, in my Apache httpd.conf file I have it set up to where I 
have a directory that is only accessible from certain IP addresses, one 
of which is 127. (the localhost).  The script I'm running is located on 
the server and the web site I'm trying to access via fopen() is on the 
same server.  Therefore, I'm thinking that the php script should have 
access to read the site's restricted directory.  For some reason it 
does not have access.

Even if it is the same server you might not connect with 127.0.0.1
as the source IP address - especially not if the other web site's host
name resolves to any other IP address than 127.0.0.1. Your tcp
connection might still be performed via the loopback-interface, but
your source IP address might still be the one of a network interface

Try to create a page on the second web site (that you want to access
thorugh fopen() )  that outputs the client's IP address. You'll
probably see that your source IP address is not 127.0.0.1.

-- 
- Peter Brodersen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen problems

2005-03-24 Thread Jason Barnett
AJ Lemke wrote:
 Hello all,

 I have an install of php on a Red Hat Ent. server that is giving me fits.
 I have been trying to use the fopen command to retreive files from external
 sites and have been getting this error:

 Warning: fopen(http://us3.php.net/images/php.gif): failed to open stream:
 HTTP request failed!  in /home/test/public_html/declare.php on line 2


Servers are occasionally down.  I think the us3 mirror was down for
quite a while today (us4, us2 and www all worked when I tried them
earlier).

In my signature do you notice how I have the php.net site without
indicating which mirror I want?  That's because making the request in
*that* way will let the php.net site determine which mirror to use for
your request.  Perhaps you will have better luck in the future if you
try to;

?php

fopen('http://php.net/images/php.gif', 'r');

?


--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins


signature.asc
Description: OpenPGP digital signature


Re: [PHP] Re: fopen

2005-03-22 Thread Richard Lynch

On Mon, March 21, 2005 9:29 pm, John Taylor-Johnston said:
   flock($results, 2); #lock file for writing
   fwrite($results, $filestr); #write $filestr to $results
   flock($results, 3); #unlock file
   fclose($results); #close file
 This is an incorrect way to try to flock a file for writing.

 You should:
 1) Open the file for READING.
 2) flock that file handle, so only YOU have access to that file.
 3) Re-open the file for WRITING, now that you have control.
 4) Write your data
 5) Release the lock.

 Could you show me a correct method, or example please? I admit I'm a
 little too newbie with flock. I have not used it since my Perl days, and
 even then ...

http://php.net/flock

has several correct examples, along with reasons when to not use flock in
the first place, as well as alternative solutions.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen

2005-03-21 Thread Richard Lynch




On Sat, March 19, 2005 6:48 am, John Taylor-Johnston said:
  chmod($defaultfile, 666);

http://php.net/chmod

has examples that tell you exactly why this is wrong...

666 is decimal.

The 666 you want is Octal.

They ain't the same number.

 What does the at_sign mean at the start of this line?

 @ $results = fopen($datafilename, w+);

@ means you are IGNORING any errors this generates.

It's usually a really bad idea unless you have some more code for error
checking.

  if (!$results) { die (Our results file could not be opened for writing.
 Your score was not recorded.  Please contact the person responsible and
 try again later.); }
  flock($results, 2); #lock file for writing
  fwrite($results, $filestr); #write $filestr to $results
  flock($results, 3); #unlock file
  fclose($results); #close file

This is an incorrect way to try to flock a file for writing.

You should:
1) Open the file for READING.
2) flock that file handle, so only YOU have access to that file.
3) Re-open the file for WRITING, now that you have control.
4) Write your data
5) Release the lock.

Your application, as it stands now, has a race condition between the open
for writing and the flock, which sooner or later, WILL bite you in the
ass.

Probably.

Maybe.

If $filestr is small enough, the Linux OS has locking built-in.  Windows
may or may not (and I don't care enough about Windows to remember, much
less look it up).  FreeBSD and other OSes may or may not also have locking
at OS layer.  I wouldn't rely on it, though, since it's trivial to do the
5 steps above.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen

2005-03-21 Thread John Taylor-Johnston
Thanks for that!
John

Richard Lynch wrote:

 On Sat, March 19, 2005 6:48 am, John Taylor-Johnston said:
   chmod($defaultfile, 666);

 http://php.net/chmod

 has examples that tell you exactly why this is wrong...

 666 is decimal.

 The 666 you want is Octal.

 They ain't the same number.

  What does the at_sign mean at the start of this line?
 
  @ $results = fopen($datafilename, w+);

 @ means you are IGNORING any errors this generates.

 It's usually a really bad idea unless you have some more code for error
 checking.

   if (!$results) { die (Our results file could not be opened for writing.
  Your score was not recorded.  Please contact the person responsible and
  try again later.); }
   flock($results, 2); #lock file for writing
   fwrite($results, $filestr); #write $filestr to $results
   flock($results, 3); #unlock file
   fclose($results); #close file

 This is an incorrect way to try to flock a file for writing.

 You should:
 1) Open the file for READING.
 2) flock that file handle, so only YOU have access to that file.
 3) Re-open the file for WRITING, now that you have control.
 4) Write your data
 5) Release the lock.

 Your application, as it stands now, has a race condition between the open
 for writing and the flock, which sooner or later, WILL bite you in the
 ass.

 Probably.

 Maybe.

 If $filestr is small enough, the Linux OS has locking built-in.  Windows
 may or may not (and I don't care enough about Windows to remember, much
 less look it up).  FreeBSD and other OSes may or may not also have locking
 at OS layer.  I wouldn't rely on it, though, since it's trivial to do the
 5 steps above.

 --
 Like Music?
 http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen

2005-03-21 Thread John Taylor-Johnston
Richard, thanks.

   chmod($defaultfile, 666);
 http://php.net/chmod
 has examples that tell you exactly why this is wrong...
 The 666 you want is Octal.

chmod($defaultfile, 0666);
Check. Thanks. Didn't pay enough attention to that.

  What does the at_sign mean at the start of this line?
  @ $results = fopen($datafilename, w+);
 @ means you are IGNORING any errors this generates.

Hmm. Thanks. Decent to know.

   flock($results, 2); #lock file for writing
   fwrite($results, $filestr); #write $filestr to $results
   flock($results, 3); #unlock file
   fclose($results); #close file
 This is an incorrect way to try to flock a file for writing.

 You should:
 1) Open the file for READING.
 2) flock that file handle, so only YOU have access to that file.
 3) Re-open the file for WRITING, now that you have control.
 4) Write your data
 5) Release the lock.

Could you show me a correct method, or example please? I admit I'm a little too 
newbie with flock. I have not used it since my Perl days, and even then ...

 http://l-i-e.com/artists.htm

Didn't know that!

Thanks,
John

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen

2005-03-19 Thread John Taylor-Johnston
Hi,
W+ does not work either.
I have resorted to adding a blank, 0 byte text file.
But it needs chmod 666.
Interesting, I add this line:

 chmod($defaultfile, 666);

and it send back an illegal error, but it appears to work anyway - the data is 
written!

What does the at_sign mean at the start of this line?

@ $results = fopen($datafilename, w+);


 try $results = fopen($datafilename, w+);

$defaultfile = /home/johj2201/public_html/ffmail.txt; #default file to write 
to
...
chmod($defaultfile, 666);
...
@ $results = fopen($datafilename, w+);
 if (!$results) { die (Our results file could not be opened for writing.  Your 
score was not recorded.  Please contact the person responsible and try again 
later.); }
 flock($results, 2); #lock file for writing
 fwrite($results, $filestr); #write $filestr to $results
 flock($results, 3); #unlock file
 fclose($results); #close file

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen

2005-03-18 Thread John Taylor-Johnston
P.S., I've checked the doc and tried a+. It still does not create ffmail.txt.

@ $results = fopen($datafilename, a+);
# Open for reading and writing; place the file pointer at the end of the file.
#If the file does not exist, attempt to create it

It does not create it.

John


 FOpen question. My script is dying. Our results file could not be opened for 
 writing
 What can I add to get more info from the die? Do I «have» to specify a 
 pathname in $defaultfile?

 John

  $defaultfile = ffmail.txt; #default file to write to
 @ $results = fopen($datafilename, a);  #open file and supress errors
  #print custom error if file doesn't exist or improper permissions
  if (!$results) { die (Our results file could not be opened for writing.); }

--
John Taylor-Johnston
-
If it's not Open Source, it's Murphy's Law.

  ' ' 'Collège de Sherbrooke:
 ô¿ôhttp://www.collegesherbrooke.qc.ca/languesmodernes/
- 819-569-2064

  °v°   Bibliography of Comparative Studies in Canadian, Québec and Foreign 
Literatures
 /(_)\  Université de Sherbrooke
  ^ ^   http://compcanlit.ca/ T: 819.569.2064

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen

2005-03-18 Thread John Taylor-Johnston
I could use:
 or die($php_errormsg);
but it is turned off in my php.ini and I can't modify it myself.

John


 FOpen question. My script is dying. Our results file could not be opened for 
 writing

 What can I add to get more info from the die?

  $defaultfile = ffmail.txt; #default file to write to
 @ $results = fopen($datafilename, a);  #open file and supress errors
  #print custom error if file doesn't exist or improper permissions
  if (!$results) { die (Our results file could not be opened for writing.); }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: fopen

2005-03-18 Thread Christopher Evans
try $results = fopen($datafilename, w+);
I am newbie at php so that may not work.
--
--chris
1-916-501-1423
a href=http://bbx.flnet.org/nxdos/;http://bbx.flnet.org/nxdos//a
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: FOPEN

2005-02-19 Thread Al
Diana Castillo wrote:
   How can I read the contents of a web page that uses basic authentication? 
I want to use fopen() but dont know how to do this and also send the 
username and password

If the webpage is your script and it is going to check the authentication stuff, 
then simply use GET arguments

fopen(http://www.example.com/path/file?user=usernamepw=password;, 'rb')
Then use
$user= $_GET['user'];
$pw= $_GET['pw'];
Check the $user and $pw for validity.
If the webpage is not yours, then see if it can accept GET arguments for 
authentication, look at your browser's address bar to gain accesss. That will be 
your complete URL.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: FOPEN

2005-02-19 Thread Rasmus Lerdorf
Al wrote:
Diana Castillo wrote:
   How can I read the contents of a web page that uses basic 
authentication? I want to use fopen() but dont know how to do this and 
also send the username and password

If the webpage is your script and it is going to check the 
authentication stuff, then simply use GET arguments

fopen(http://www.example.com/path/file?user=usernamepw=password;, 'rb')
Then use
$user= $_GET['user'];
$pw= $_GET['pw'];
Check the $user and $pw for validity.
If the webpage is not yours, then see if it can accept GET arguments for 
authentication, look at your browser's address bar to gain accesss. That 
will be your complete URL.
The syntax for basic auth is actually:
  http://user:[EMAIL PROTECTED]
-Rasmus
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: fopen errors

2004-02-18 Thread Paul Furman
Admin wrote:
Here is the code I am using:

$fileHandle = fopen($fileUpload, r);
$fileContent = fread($fileHandle, $fileUpload_size);
$fileContent = addslashes($fileContent);
Warning: fopen(C:\\0-temp\\100_0078.jpg, r) -No such file or
directory in /var/www/testbed/httpdocs/blob/grabfile.php on line 41
Then only thing that really jumps out at me in the file source path of
C:\\0-temp\\100_0078.jpg  there is a couple of extra Backslashes (\)
in the path statement.
I am using a sample script that pulled from one of the websites.


Have you tried single forward slashes?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: fopen does not open URL-files

2003-12-20 Thread Taras V. Panchenko

I tried, but I receive the new error:

Warning: fopen(): php_network_getaddresses: getaddrinfo failed: Name or
service not known in /home/manageme/public_html/try-test/fopen-test-http.php
on line 7

Warning: fopen(http://www.management.kiev.ua/MO/main.php/): failed to open
stream: Permission denied in
/home/manageme/public_html/try-test/fopen-test-http.php on line 7

Why there are errors in this simple command? What are
'php_network_getaddresses' and 'getaddrinfo' ?

Thanx,
Taras V. Panchenko.


Eric Bolikowski [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 Taras Panchenko [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]

  I have 2 questions:
  1) why gethostbyname() does not resolve my host name into IP?
  2) why fopen() (and file()) does not open an external (URL) file via
http?
  Please, see my example below:
  --
 

http://www.management.kiev.ua/try-test/fopen-test-http.php -
  --
  ?
  echo gethostbyname(www.management.kiev.ua);
 
  $h=fopen(http://www.management.kiev.ua/MO/main.php;, r);
  echo fread($h,200);
  ?

 Try this rather(maybe it works):

 ?php

 $fp=fopen(http://www.management.kiev.ua/MO/main.php/;, r);
  echo fread($fp,200);
 ?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen does not open URL-files

2003-12-18 Thread Eric Bolikowski

Taras Panchenko [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I have 2 questions:
 1) why gethostbyname() does not resolve my host name into IP?
 2) why fopen() (and file()) does not open an external (URL) file via http?
 Please, see my example below:
 --

http://www.management.kiev.ua/try-test/fopen-test-http.php -
 --
 ?
 echo gethostbyname(www.management.kiev.ua);

 $h=fopen(http://www.management.kiev.ua/MO/main.php;, r);
 echo fread($h,200);
 ?
 - browser (interpreted) result ---
 www.management.kiev.uabr /
 bWarning/b:  fopen() [a
 href='http://www.php.net/function.fopen'function.fopen/a]:
 php_network_getaddresses: getaddrinfo failed: No address associated with
 hostname in b/home/manageme/public_html/try-test/fopen-test-http.php/b
 on line b4/bbr /
 br /
 bWarning/b:  fopen(http://www.management.kiev.ua/MO/main.php) [a
 href='http://www.php.net/function.fopen'function.fopen/a]: failed to
 create stream: Permission denied in
 b/home/manageme/public_html/try-test/fopen-test-http.php/b on line
 b4/bbr /
 br /
 bWarning/b:  fread(): supplied argument is not a valid stream resource
 in b/home/manageme/public_html/try-test/fopen-test-http.php/b on line
 b5/bbr /
  or as plain text --
 www.management.kiev.ua
 Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo
 failed: No address associated with hostname in
 /home/manageme/public_html/try-test/fopen-test-http.php on line 4

 Warning: fopen(http://www.management.kiev.ua/MO/main.php)
[function.fopen]:
 failed to create stream: Permission denied in
 /home/manageme/public_html/try-test/fopen-test-http.php on line 4

 Warning: fread(): supplied argument is not a valid stream resource in
 /home/manageme/public_html/try-test/fopen-test-http.php on line 5
 

 Thanks a lot for help in advance,
 Taras V. Panchenko.

Try this rather(maybe it works):

?php

$fp=fopen(http://www.management.kiev.ua/MO/main.php/;, r);
 echo fread($fp,200);
?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen custom 404 issue

2003-12-10 Thread Justin Patrin
Mike D wrote:
I am trying to read in a particular page to a variable. How do you handle if
the page is a 404 and then redirects to a custom error page? Am I supposed
to use fsockopen and read headers or ?? Ideally I need to pull the
end-result page to search for a string in it.
Here's the code

$handle = fopen(http://www.amazon.com/exec/obidos/ISBN=12345678;, rb);
$contents = ;
do 
{
 $data = fread($handle, 8192);
 if (strlen($data)==0)
 break;
 $contents .= $data;
} while(true);
fclose ($handle);

Thanks guys


Mike Dunlop
AWN, Inc.
// www.awn.com
[ e ] [EMAIL PROTECTED]
[ p ] 323.606.4237
You can use PEAR's HTTP_Request, which will do redirects for you (and 
lots of other stuff ;-).
http://pear.php.net/package/HTTP_Request

--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: fopen

2003-03-16 Thread Coert Metz
Hi

If i'm reading your code in the right way, i think
you can better use the file_exists function available
in php
Read the manual at:
http://www.php.net/manual/nl/function.file-exists.php
Many success

Coert Metz

Sebastian wrote:
hello,

i have this snippet of code, from what i can tell it works .. just wondering
if i am doing it in a correct way, or if there is a better, or faster way.
thanks for any input.
$fp = @fopen($_SERVER[DOCUMENT_ROOT]/images/$mapname.jpg,r);

if ( $fp )
 {
 $mappic = img border=\0\ src='/images/mappics/$mapname.jpg'/a;
}
else
 {
 $mappic = img border=\0\ src='/images/noimage.gif';
 }
@fclose ( $fp );
echo $mappic;

cheers,
- Sebastian


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: fopen/fgets

2003-03-07 Thread Bryan Koschmann - GKT
Thanks.. I feel stupid, I wasn't paying attention. *sigh* seems to work
now :)

Bryan

On Fri, 7 Mar 2003, Adrian Ciutureanu wrote:

|you close the input file in while loop ( fclose($fp); )
|
|Bryan Koschmann - Gkt [EMAIL PROTECTED] wrote in message
|news:[EMAIL PROTECTED]
| Can someone give me a hand here? I am really lost as to what is
|going on.
| I have a file that looks like this
|
| user1,Store 1 - ABC street
| user2,Store 2 - Northside
| user3,Store 3 - East
|
| I try to run my code, but I get a php log filled (~33 megs, the
|input file
| is only 12 lines):
|
| [06-Mar-2003 15:22:53] PHP Warning:  feof(): 1 is not a valid
|File-Handle
| resource in /home/perf/create_prefs.php on line 7
| [06-Mar-2003 15:22:53] PHP Warning:  fgets(): 1 is not a valid


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen/fgets

2003-03-06 Thread Adrian Ciutureanu
you close the input file in while loop ( fclose($fp); )

Bryan Koschmann - Gkt [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Can someone give me a hand here? I am really lost as to what is
going on.
 I have a file that looks like this

 user1,Store 1 - ABC street
 user2,Store 2 - Northside
 user3,Store 3 - East

 I try to run my code, but I get a php log filled (~33 megs, the
input file
 is only 12 lines):

 [06-Mar-2003 15:22:53] PHP Warning:  feof(): 1 is not a valid
File-Handle
 resource in /home/perf/create_prefs.php on line 7
 [06-Mar-2003 15:22:53] PHP Warning:  fgets(): 1 is not a valid
File-Handle
 resource in /home/perf/create_prefs.php on line 8
 [06-Mar-2003 15:22:53] PHP Warning:  feof(): 1 is not a valid
File-Handle
 resource in /home/perf/create_prefs.php on line 7
 [06-Mar-2003 15:22:53] PHP Warning:  fgets(): 1 is not a valid
File-Handle
 resource in /home/perf/create_prefs.php on line 8

 While it is running it just stalls.

 This is my code:

 $fp = fopen(emaillist, r);
 if (!$fp)
 die(Error opening file. $php_errormsg);

 while (!feof($fp)) {
 $buffer = fgets($fp, 4096);
 echo $buffer;
 $row = explode(',', $buffer);
 if (!empty($row[0])) {
 $user = $row[0];
 $name = $row[1];
 $stuff = [EMAIL PROTECTED] .

chosen_theme\=../themes/mystore_theme.php\n .
 show_html_default\=0\n .
 javascript_on\=1\n .
 full_name\=$name\n .
 use_signature\=0\n .
 prefix_sig\=0\n;

 $fileout = $user . _perf.pref;
 $fout = fopen($fileout, w);
 fputs($fout, $stuff);
 fclose($fp);
 fclose($fout);
 }
 }


 Please help! I keep re-reading the docs at php.net for fopen fgets
and all
 that with no luck!

 Thanks,

 Bryan




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen

2003-03-05 Thread KK
the @ before the fopen just tells php to suppress the error message if it
can't open the file.
that's all it does.

John Taylor-Johnston [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 #http://www.php.net/manual/en/function.fopen.php

 $contents = fopen (/home/pathto/file.txt, r);

 if ($contents){echotextarea$contents/textarea;}
 else{echo no contents there;}

 Questions:
 What is the use of @fopen?
 Does anyone see a better way?




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fopen

2003-03-05 Thread John Taylor-Johnston
MatTo get data out of the file that you
Mathave opened, you will need to read() it n.
Mathttp://www.php.net/manual/en/function.fread.php

Ok, how about this? What about error checking if the file contains something as I 
include below? Is that enough?

?php
// get contents of a file into a string
$filename = /usr/local/something.txt;
$handle = fopen ($filename, r);
$contents = fread ($handle, filesize ($filename));
fclose ($handle);

if ($contents){echotextarea$contents/textarea;}
else{echo no contents there;}
?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: fOpen in append mode on a FTP Server

2002-12-30 Thread Elna Moorhouse
To see the error in action go to http://www.moorhouse.co.za/test.php

Please help!
Thanks
  Elna Moorhouse [EMAIL PROTECTED] wrote in message 
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...

  What I want to do is very simple,  I have a txt file on a ftp server, that contains 
the number of visits to my site.  I manage to open the file with 
fopen($filename,r+), but the information is not written to the file.  I know that 
on a ftp server one can only open a file with fopen for read OR write, so I have 
changed the fOpen to fopen($filename,a) or fopen($filename,w) .  This does not 
work as I am getting a warning message that the file already exist and fopen fails.  
My ISP did not compile PHP with FTP enabled, so I can not use an FTP session to delete 
the file before attempting to write to the file.  Is there any other way of deleting 
the file, without using an FTP session.  Below is an extract from my code, if it will 
help:

  ? 
$sFileName = ftp://myuser:[EMAIL PROTECTED]/folder/Counter.txt;;
  
   $sOutput = 12345
  
   $file = fopen ($sFileName, 'r+');
   if (!$file) {
   echo pUnable to open hitcounter file - File is temporary unavailable\n;
   return $result;
}
$written = fwrite($file, $sOutput);
if ($written = 0) {
   echo pUnable to write hitcounter, file is  temporary unavailable\n;
   fclose($file);
   return $result;
} 
fclose($file);

  ?

  With mode = r+, I get a $written as 22, but it is not written to the file
  With mode = a or w, fopen fails.

  I have been trying to get this resolved for some time now and can not get it to 
work.  I am a novice PHP writer, please help!





[PHP] Re: fopen()

2002-09-19 Thread Jason Morehouse

Yup!

On Thu, 19 Sep 2002 16:43:48 -0700, Donahue Ben wrote:

 I have a php script that tries to write files in a
 particular directory.  When the script writes files
 the ownership is apache.  The problem I have is the
 particular directory that the script is trying to
 create files in, it cannot, because it does not own
 that directory and it is not part of the group.  So is
 the only way to get around this problem is by changing
 the ownership of the directory to apache?
 
 Ben
 
 __
 Do you Yahoo!?
 New DSL Internet Access from SBC  Yahoo!
 http://sbc.yahoo.com

-- 
 Jason Morehouse (jm[@]netconcepts[.]com)
 Netconcepts - http://www.netconcepts.com
 Auckland, New Zealand
 Linux: Because rebooting is for adding hardware.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: fopen() and flock()

2002-09-02 Thread nicos

Hi,

You should use a while(!feof) syntax so that can verify that the file is
not empty.
You should also use
$text =  implode(,@file($filename));
Thats the easiest way to read a file. It will put each lines into an
array and you will just implode it into a variable

--
Merci de nous avoir choisi. - Thanks you for your choice.
Nicos - CHAILLAN Nicolas
[EMAIL PROTECTED]
[EMAIL PROTECTED]
www.GroupAKT.com - Hébergement Group.
www.WorldAKT.com - Hébergement de sites Internet
David McInnis [EMAIL PROTECTED] a écrit dans le message de news:
021001c25210$21c38010$[EMAIL PROTECTED]
 I use fopen() in a template system that I have developed.  I noticed
 that occasionally I get blank pages served up.  Here is one of my
 snippets.

 $filename = $ROOTDIR/content/myfile.txt;
 $fd = fopen ($filename, r);
 $PAGE_CONTENT  = fread ($fd, filesize ($filename));
 fclose ($fd);

 Doing this I get the contents of the file read into the $PAGE_CONTENT
 variable.

 I never use fopen() to write to files.  Only read with the r
 directive.  So what could be causing my conflicts?  Do I need to flock
 the file to shared?

 I am running Linux PHP, Apache and Linux.

 David McInnis




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: fopen(http:...) problems

2002-08-20 Thread php

Why don't you try chmoding the file 777.
Next use readfile:
http://www.php.net/manual/en/function.readfile.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: fopen and sort by date modified

2002-08-14 Thread lallous

checkout:

opendir()
readdir()
fstat()
closedir()

Elias
Electroteque [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 hi there i was wondering how i could fopen a directory and then sort the
 files by date modified is there a way ?





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Fopen errors out when opening a URL

2002-07-18 Thread Richard Lynch

I am trying to do a simple fopen(http://www.weather.com/index.html;, r); 
For some reason I cannot Open any URL's after trying several.

I get the following error 

Warning: stat failed for Resource id #1 (errno=2 - No such file or
directory)

It's possible that weather.com is sending cookies and refusing access if you
aren't logged in or something...

To be sure, SSH (telnet) in to your server, or open an MS-DOS shell, and do
this from a command prompt:

telnet www.weather.com 80
GET /index.htm HTTP/1.0
host: www.weather.com


Hit 'return' twice after that last line, and be ready for a lot of crap to
come out.  Or not.  Whatever you see there is what PHP is seeing, almost for
sure.

I think cURL might be the easiest way around that, though I hate to put cURL
and easy in the same sentence.

-- 
Like Music?  http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: fopen r+ not working - how to add to beginning of txt file

2001-11-21 Thread Richard Lynch

Brian Tully wrote:

 i've been going crazy trying to figure out how to add news items to the
 top of an already existing txt file containng previous news posts. While
 I'd love to change the system so everything is database-driven (as most of
 the rest of the site is), this news area has so much news posts that it
 would take forever to convert the info the database.

Convert to database.  Your hair and your aspirin intake will thank you.

 Even though the r+
 option is supposed to put the pointer at the beginning of the file

This is correct and is working.

 and add
 to it as opposed to overwriting

This is simply not correct!

r+ does not do any magic.  It puts the file pointer at the beginning of the 
file, but it does *NOT* insert into the file.  files just don't work like 
that.  r+ is *DESIGNED* to let you over-write a file, not put stuff into 
the top of it.  That's why databases were invented. :-)

 Is there a better way to accomplish what I'm trying to do?

Use a database.

If you really, really, really, absolutely insist on sticking to a 
file-based system, you *COULD* append the new stuff at the end, and then 
use fopen/fseek to *FIND* the newer stuff.  Or if the files are small 
enough use http://php.net/file to suck the whole thing into an array and 
interate through it backwards.

But if the files are big as you claim, then neither of these options is 
really going to be all that fast.  Convert to a database.

One *other* option is to store each article in a different file with the 
date as the name of the file, and then you can snag the new articles fairly 
quickly by using the file name as the key...  Even that won't be as fast 
and easy as a database.  Use a database.

Have I said Use a database enough times yet?

-- 
Like music?  http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: fopen for ftp transfers

2001-10-29 Thread CC Zona

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Scott) wrote:

 I am attempting to transfer files from one server to another via ftp.  I 
 am wondering if this is the best method to transfer files within PHP or
 should I seek other methods.  Here is the way I am doing it now:
 
 $sendfile =
 fopen(ftp:user:[EMAIL PROTECTED]/testfile, w);

http://php.net/ftp

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: fopen !!!

2001-10-02 Thread Richard Lynch

If you are worried about this, you should probably use a database which will
take care of this for you...

It is possible to use http://php.net/flock to lock the file, pretty much
like the example in the manual, and then 4999 users will have to wait until
the one editor is finished...

You'll still need to be sure that those 4999 users then get the most current
version before they start editing, so you'll need to check what they have
now with what's in there before you let them blindly replace it...

You're *REALLY* better off doing that with a database.

*NOTHING* will truly allow you to do what you describe easily...

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
- Original Message -
From: Kmarada [EMAIL PROTECTED]
Newsgroups: php.general
To: [EMAIL PROTECTED]
Sent: Tuesday, October 02, 2001 1:57 PM
Subject: fopen !!!


 is it possible to use fopen to open 5000 files differents simultaneous and
 edit it simultaneous ?

 I have one file. if four user edit it simultaneous what happen? there is
 something to lock the file until one finish to edit?
 I read at manual something like flock how can i use it?








-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: fopen

2001-09-30 Thread Martin

Kmarada schrieb:

 is it possible to use fopen to open 5000 files differents simultaneous and
 edit it simultaneous ?

I think, this depends how many files your operating-system can handle.

 i have one file. if four user edit it simultaneous what happen? there is
 something to lock the file until one finish to edit?

see flock.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: fopen

2001-09-30 Thread Kmarada

I read the manual but i still don't know how to use flock do you have an
exemple?
flock works on windows2000 ?

Martin [EMAIL PROTECTED] escreveu nas notícias de
mensagem:[EMAIL PROTECTED]
 Kmarada schrieb:

  is it possible to use fopen to open 5000 files differents simultaneous
and
  edit it simultaneous ?

 I think, this depends how many files your operating-system can handle.

  i have one file. if four user edit it simultaneous what happen? there is
  something to lock the file until one finish to edit?

 see flock.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Re: fopen, fread

2001-09-22 Thread Philip Olson

Yeah, filesize() does not work with urls.  Suggested file() and implode()
earlier for this task and didn't mention fgets() as it may be appropriate
here as well.

  http://www.php.net/fgets
  http://www.php.net/file

Both manual entries have examples that do exactly what you want, Put a
url contents into a string. fgets() is nice because you don't have to
gets the entire file, sticking a break; in there during a match can be
uber cool :-)

If this is being done locally then of course don't go through http:// ...

Regards,
Philip Olson



On Sun, 23 Sep 2001, Simon Roberts wrote:

 Check the value of filesize($fileName).  It's probably not working - either
 because PHP doesn't support it with URLs (likely) or that it's can't get the
 length from the webserver (less likely).
 
 PS: don't cross-post this sort of message to php-dev. That's for people
 developing PHP, not developing *in* PHP.
 
 - Original Message -
 From: CC Zona [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Saturday, September 22, 2001 4:32 PM
 Subject: [PHP-DEV] Re: fopen, fread
 
 
  In article [EMAIL PROTECTED],
   [EMAIL PROTECTED] (Dries Plessers) wrote:
 
   Can anybody tell me what is wrong.  $file contains nothing ?
 
   $fileName=http://www.proxis.com;;
   $fp=fopen($fileName, r);
   $file=fread($fp, filesize($fileName));
   fclose($fp);
   print($file);
 
  Not a good idea to just assume that every fopen will be successful (and
  therefore go ahead with the read) or that every fread will be successful
  (and therefore go ahead with the print).  Throw some error checking in
  there, and PHP will likely tell you where the code is failing and why.
 
  --
  CC
 
  --
  PHP Development Mailing List http://www.php.net/
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: FOPEN remote problems..

2001-09-17 Thread _lallous

I tried to get it via CURL but i failed, here's the output:
* Connected to www.800.com (216.88.211.1)
 GET /prod.asp?P=5261 HTTP/1.1
User-Agent: curl/7.8 (win32) libcurl 7.8
Host: www.800.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
* Closing live connection (#0)

I tried with NetVampire (which allow you to specifiy a user agent string),
and I succeeded, here's output:
  Connecting to www.800.com ...
  Connected to www.800.com [216.88.211.1]
  GET /prod.asp?P=5261 HTTP/1.1
  Connection: close
  Host: www.800.com
  Accept: */*
  Pragma: no-cache
  Cache-Control: no-cache
  Referer: http://www.800.com/
  User-Agent: Mozilla/4.04 [en] (Win95; I ;Nav)
  Cookie: SITESERVER=GUID=5003bed94ac9ead4d5b3fcd703c59b91;
MemRightsChanged=jtalOx==; popup=1

  HTTP/1.0 200 OK
  Server: Microsoft-IIS/5.0
  Date: Mon, 17 Sep 2001 10:58:16 GMT
  P3P: policyref=http://www.800.com/w3c/p3p.xml;, CP=ADM DEV CUS TAI STP
UNI STA OUR DSP ALL COR
  Content-Length: 51076
  Content-Type: text/html
  Cache-Control: private
  X-Cache: MISS from gw.inet.gw
  Connection: close

  Data transfer started
  Received 51 076 bytes in 0:00:08 (5 686 bytes/s)
  JOB COMPLETED SUCCESSFULLY

I'm not sure then if the problem is with user agent or not

Reberrya [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hey all.  I'm trying to do a fopen for reading on many different sites and
 web pages.  However, I have found that many webpages can not be FOPENed at
 all.  For instance, one such example would be
 http://www.800.com/prod.asp?P=5261

 I do not understand as I can read from numerous other sites.  Why can I
see
 the above site and others in Internet Explorer and Netscape, but PHP is
not
 able to read from that file?

 And yes, I can read from many other ASP, JSP, and PHP pages, so this is
not
 the problem that I know of.

 Any help appreciated.

 Andrew





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Re: fopen a URL with = in it

2001-08-03 Thread Corey Chapman

So you're saying that I should be able to pass the = sign in just fine 
into the fopen call with no errors? I understand what you mean that if 
= was what the variable was defined as, then THAT is where I'd use 
urlencode ;) I wasn't too sure about that, but now I am.

Quite odd that it reports errors then when passing in an = sign. 
Perhaps PHP does not like to load url's like that.. 

 You would only want URLEncode if thething had the = in it as part 
of the
 data...
 
 http://whatever.com/foo.php?operand=; . urlencode(=)
 
 might be a URL for math geeks to talk about the = sign :-)
 
 --
 WARNING [EMAIL PROTECTED] address is an endangered species -- Use
 [EMAIL PROTECTED]
 Wanna help me out?  Like Music?  Buy a CD: http://l-i-
e.com/artists.htm
 Volunteer a little time: http://chatmusic.com/volunteer.htm
 - Original Message -
 From: Corey Chapman [EMAIL PROTECTED]
 Newsgroups: php.general
 To: [EMAIL PROTECTED]
 Sent: Friday, August 03, 2001 1:45 PM
 Subject: fopen a URL with = in it
 
 
  Something that's been driving me crazy for a few days. Could it
  be a bug in PHP?
 
  Using the fopen function (or even the file function), I want to 
open a
  web page for read. Sounds easy? Well, say I want to have an = 
sign in
  the URL.. well that is where the problem comes. I have tried things
  like this:
 
  $eq = urlencode(=);
  $URL = http://www.something.com/file.php?thing.$eq.thething;;;
 
  I have tried many other combinations as well.. the problem is this:
  when PHP calls fopen(), it does not allow the = sign in the variable
  passed in. So I figured I should escape it..
 
  fopen(http://www.something.com/file.php?thing\=thething,r;;);
 
  But that did not work either. It allows me to pass it in, but then 
it
  tries to open the literal \= in the url, which of course doesn't
  exist. The url has just an =. I thought encoding the whole or part 
URL
  would work. well it loads the page, but the page itself doesn't
  recognize the encoded = sign as being an = sign..
 
  Bah! Anyone have any ideas.. ?
 
 
  Corey Chapman
  Xnull CEO
  (Chat with us: http://forum.xnull.com)
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: php-list-
[EMAIL PROTECTED]
 
 
 

Corey Chapman
Xnull CEO
(Chat with us: http://forum.xnull.com)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: fopen(fd, w) doesn't work?

2001-08-01 Thread Keith Jeffery

for the first part, make sure that you have write permission to the
directory specified, and for the second, you can't open a file for writing
from a remote location.

Keith Jeffery
[EMAIL PROTECTED]

Ibrahim Noor [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Dear all,

 I'm newbie with PHP, but it so nice for me.

 I tried to create file by fopen(fd, w) function, but it didn't work.
 Permission Denied, server said.

 I tried with fopen(ftp://user@pass:ftp.server.com/test.txt;, w) the
 address I changed according to my server host, but once again server said:
 Permission Denied.

 It host at a free web hosting, with PHP3.

 Can you help me to make it work.

 Thank you all.

 Ibrahim


 _
 Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]