php-general Digest 11 Apr 2011 13:25:34 -0000 Issue 7268

Topics (messages 312327 through 312334):

socket_connect() unable to connect [115]: Operation now in progress
        312327 by: Paul McGarry

Re: File Upload Problem
        312328 by: Louis Huppenbauer
        312334 by: Hans Åhlin

Re: Silly question
        312329 by: Stuart Dallas
        312330 by: Curtis Maurand
        312331 by: Stuart Dallas
        312332 by: Richard Quadling

stupid array question
        312333 by: Curtis Maurand

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hi all,

Can anyone explain why I might get a:

socket_connect(): unable to connect [115]: Operation now in progress

error on a blocking socket?

The documentation seems to suggest that is a 'normal' response for a
non-blocking socket but I am seeing it on a blocking socket.

Example code:
====
                $this->logSocket = socket_create ( AF_INET,
SOCK_STREAM, SOL_TCP );
                socket_set_block($this->logSocket);
                socket_set_option ( $this->logSocket, SOL_SOCKET,
SO_SNDTIMEO, array ('sec' => 2, "usec" => 0 ) );
                $this->loggerConnected = socket_connect (
$this->logSocket, $this->logHost, $this->logPort );
                if (! $this->loggerConnected)
                        user_error ( 'Error connecting to ' .
$this->logHost . ' ' . $this->logPort );
====

The port it is connecting to is running on localhost. It works roughly
99.9% of the time but occasionally fails with the error above.

Paul

--- End Message ---
--- Begin Message ---
Is there already a file with the same name?
Apparently copy won't overwrite a file on windows if it already exists.

Maybe you have the same problem ffproberen2 at dodgeit dot com had on
the php.net/move_uploaded_file manpage?

2011/4/10 tedd <[email protected]>:
> At 7:15 AM +0200 4/7/11, Wojciech Kupiec wrote:
>>
>> On 06/04/11 19:10, tedd wrote:
>>>
>>> -snip-
>>> What could be wrong? What should I be looking for?
>>
>> If you really want to get help, publish your code.
>
> I don't think that's true. I should be able to ask a technical question with
> observations and inquire as to "What's wrong?" After all, what's the point
> of showing code that works on two servers, but fails on a third? Really,
> what is that going to tell you?
>
> As for the uploaded file exceeding "max file size" and "file_uploads"
> enabled, those are obvious and I did that investigation before I posted the
> question. They are NOT the problem.
>
> I also checked all the servers involved for "safe_mode" and "open_basedir"
> settings and they are set the same. Additionally, the "upload_max_filesize"
> and "upload_tmp_dir" are also set exactly the same. As such, I don't know
> what else to look for -- hence my question.
>
> As I said, the script works on two servers, but fails on a third.
>
> This is what I've learned in addition to the above:
>
> The script does successfully upload the file to the server in question. For
> example, I receive "truth" from:
>
> if(is_uploaded_file($_FILES['userfile']['tmp_name']))
>   {
>   echo('true');
>   }
>
> I can even get the contents of the uploaded file by:
>
> $contents = file_get_contents($_FILES['userfile']['tmp_name']);
> echo($contents);
>
> -- and the contents are displayed.
>
> So, the file is indeed uploaded!
>
> What I cannot do is move the file to another location using:
>
> $result = move_uploaded_file($_FILES['userfile']['tmp_name'], $path . '/' .
> $_FILES['userfile']['name']);
>
> (Yes, all possible file paths have been investigated)
>
> Nor, can I copy the file by:
>
> $result = copy($_FILES['userfile']['tmp_name'], $path . '/' .
> $_FILES['userfile']['name']);
>
> The only difference I see is the server causing problems is Windows NT
> whereas the others are Linux.
>
> So, knowing this  -- does anyone have any idea as to what is wrong?
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
I had some similar problem with Windows 7,
it had to do with UAC and folder rights. Apache/PHP could read but not
write to any dir except the ones that all users could write to.
I solved it by allowing every one to read, write and change content in
the directory where I needed PHP to handle/control the content.


2011/4/10 tedd <[email protected]>:
> At 7:15 AM +0200 4/7/11, Wojciech Kupiec wrote:
>>
>> On 06/04/11 19:10, tedd wrote:
>>>
>>> -snip-
>>> What could be wrong? What should I be looking for?
>>
>> If you really want to get help, publish your code.
>
> I don't think that's true. I should be able to ask a technical question with
> observations and inquire as to "What's wrong?" After all, what's the point
> of showing code that works on two servers, but fails on a third? Really,
> what is that going to tell you?
>
> As for the uploaded file exceeding "max file size" and "file_uploads"
> enabled, those are obvious and I did that investigation before I posted the
> question. They are NOT the problem.
>
> I also checked all the servers involved for "safe_mode" and "open_basedir"
> settings and they are set the same. Additionally, the "upload_max_filesize"
> and "upload_tmp_dir" are also set exactly the same. As such, I don't know
> what else to look for -- hence my question.
>
> As I said, the script works on two servers, but fails on a third.
>
> This is what I've learned in addition to the above:
>
> The script does successfully upload the file to the server in question. For
> example, I receive "truth" from:
>
> if(is_uploaded_file($_FILES['userfile']['tmp_name']))
>   {
>   echo('true');
>   }
>
> I can even get the contents of the uploaded file by:
>
> $contents = file_get_contents($_FILES['userfile']['tmp_name']);
> echo($contents);
>
> -- and the contents are displayed.
>
> So, the file is indeed uploaded!
>
> What I cannot do is move the file to another location using:
>
> $result = move_uploaded_file($_FILES['userfile']['tmp_name'], $path . '/' .
> $_FILES['userfile']['name']);
>
> (Yes, all possible file paths have been investigated)
>
> Nor, can I copy the file by:
>
> $result = copy($_FILES['userfile']['tmp_name'], $path . '/' .
> $_FILES['userfile']['name']);
>
> The only difference I see is the server causing problems is Windows NT
> whereas the others are Linux.
>
> So, knowing this  -- does anyone have any idea as to what is wrong?
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 


**********************************************
 Hans Åhlin
   Tel: +46761488019
   icq: 275232967
   http://www.kronan-net.com/
   irc://irc.freenode.net:6667 - TheCoin
**********************************************

--- End Message ---
--- Begin Message ---
On Monday, 11 April 2011 at 02:12, Curtis Maurand wrote:
nevermind. There is a function: fgetcsv();

Ewww!

http://blog.ericlamb.net/2010/01/parse-apache-log-files-with-php/

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


> Curtis Maurand wrote:
> > 
> > 
> > Hello,
> > I'm trying to run through an apache log
> file in an attempt to
> > get all of the user agents.
> > 
> > The question is how do I split the
> > string? I can't
> seem to find a workable delimiter. Each
> > section of the
> file is enclosed in quotes and that should be helpful, but
> > it
> doesn't seem to be. I can't seem to set the delimiter to '"
> "' I can't
> > seem to find any good
> > examples,
> either.
> > 
> > I can't split on spaces, because the user
> > agents generally have spaces in them.
> > 
> > I was
> trying to use
> > explode. 
> print_r(explode('" "', $line);
> > 
> > Any help
> > would be appreciated.
> > thanks,
> > Curtis
> 


--- End Message ---
--- Begin Message ---

Stuart Dallas wrote:
> On Monday, 11 April 2011 at 02:12, Curtis
Maurand wrote:
> nevermind. There is a function: fgetcsv();
> 
> Ewww!

Say what you want, it works.  Your
solution is way more elegant.  regex's are not my strong suit. 
I have to have the regex pocket reference to understand that regex 
that's in there.  However, the fgetcsv breaks it up into a few chunks
and I have to break up the first chunk, but that's space delimited, so its
not so bad.  I'll probably use yours.  Thanks for the class.

> 
>
http://blog.ericlamb.net/2010/01/parse-apache-log-files-with-php/
> 
> -Stuart
> 
> --
> Stuart
Dallas
> 3ft9 Ltd
> http://3ft9.com/
> 
>

>> Curtis Maurand wrote:
>> >
>>
>
>> > Hello,
>> > I'm trying to run
through an apache log
>> file in an attempt to
>>
> get all of the user agents.
>> >
>> > The
question is how do I split the
>> > string? I can't
>> seem to find a workable delimiter. Each
>> >
section of the
>> file is enclosed in quotes and that should be
helpful, but
>> > it
>> doesn't seem to be. I
can't seem to set the delimiter to '"
>> "' I
can't
>> > seem to find any good
>> >
examples,
>> either.
>> >
>> > I
can't split on spaces, because the user
>> > agents
generally have spaces in them.
>> >
>> > I
was
>> trying to use
>> > explode.
>>
print_r(explode('" "', $line);
>> >
>>
> Any help
>> > would be appreciated.
>> >
thanks,
>> > Curtis
>>
> 
>

--- End Message ---
--- Begin Message ---
On Monday, 11 April 2011 at 13:17, Curtis Maurand wrote:
Stuart Dallas wrote:
> > On Monday, 11 April 2011 at 02:12, Curtis Maurand wrote:
> > nevermind. There is a function: fgetcsv();
> > 
> > Ewww!
> 
> Say what you want, it works. Your solution is way more elegant. regex's are 
> not my strong suit. I have to have the regex pocket reference to understand 
> that regex that's in there. However, the fgetcsv breaks it up into a few 
> chunks and I have to break up the first chunk, but that's space delimited, so 
> its not so bad. I'll probably use yours. Thanks for the class.

I'm not a great regex guru either, I googled that - it's not my class.

You can use a hammer to knock in a screw, but when screwdrivers are 
ubiquitously lying around all over the internet, why would you?!

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


> > 
> > http://blog.ericlamb.net/2010/01/parse-apache-log-files-with-php/
> > 
> > -Stuart
> > 
> > --
> > Stuart Dallas
> > 3ft9 Ltd
> > http://3ft9.com/
> > 
> > 
> > > Curtis Maurand wrote:
> > > > 
> > > > 
> > > > Hello,
> > > > I'm trying to run through an apache log
> > > file in an attempt to
> > > > get all of the user agents.
> > > > 
> > > > The question is how do I split the
> > > > string? I can't
> > > seem to find a workable delimiter. Each
> > > > section of the
> > > file is enclosed in quotes and that should be helpful, but
> > > > it
> > > doesn't seem to be. I can't seem to set the delimiter to '"
> > > "' I can't
> > > > seem to find any good
> > > > examples,
> > > either.
> > > > 
> > > > I can't split on spaces, because the user
> > > > agents generally have spaces in them.
> > > > 
> > > > I was
> > > trying to use
> > > > explode.
> > > print_r(explode('" "', $line);
> > > > 
> > > > Any help
> > > > would be appreciated.
> > > > thanks,
> > > > Curtis
> 


--- End Message ---
--- Begin Message ---
On 11 April 2011 13:23, Stuart Dallas <[email protected]> wrote:
> On Monday, 11 April 2011 at 13:17, Curtis Maurand wrote:
> Stuart Dallas wrote:
>> > On Monday, 11 April 2011 at 02:12, Curtis Maurand wrote:
>> > nevermind. There is a function: fgetcsv();
>> >
>> > Ewww!
>>
>> Say what you want, it works. Your solution is way more elegant. regex's are 
>> not my strong suit. I have to have the regex pocket reference to understand 
>> that regex that's in there. However, the fgetcsv breaks it up into a few 
>> chunks and I have to break up the first chunk, but that's space delimited, 
>> so its not so bad. I'll probably use yours. Thanks for the class.
>
> I'm not a great regex guru either, I googled that - it's not my class.
>
> You can use a hammer to knock in a screw, but when screwdrivers are 
> ubiquitously lying around all over the internet, why would you?!
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>
>
>> >
>> > http://blog.ericlamb.net/2010/01/parse-apache-log-files-with-php/
>> >
>> > -Stuart
>> >
>> > --
>> > Stuart Dallas
>> > 3ft9 Ltd
>> > http://3ft9.com/
>> >
>> >
>> > > Curtis Maurand wrote:
>> > > >
>> > > >
>> > > > Hello,
>> > > > I'm trying to run through an apache log
>> > > file in an attempt to
>> > > > get all of the user agents.
>> > > >
>> > > > The question is how do I split the
>> > > > string? I can't
>> > > seem to find a workable delimiter. Each
>> > > > section of the
>> > > file is enclosed in quotes and that should be helpful, but
>> > > > it
>> > > doesn't seem to be. I can't seem to set the delimiter to '"
>> > > "' I can't
>> > > > seem to find any good
>> > > > examples,
>> > > either.
>> > > >
>> > > > I can't split on spaces, because the user
>> > > > agents generally have spaces in them.
>> > > >
>> > > > I was
>> > > trying to use
>> > > > explode.
>> > > print_r(explode('" "', $line);
>> > > >
>> > > > Any help
>> > > > would be appreciated.
>> > > > thanks,
>> > > > Curtis
>>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Certain data sequences (especially like the Apache log file), are well
documented and as such, due to their regular format, are sometimes
easier to read using a regex than by manually pulling apart using
string functions.

I use an app called RegexBuddy (it's a windows app) which is really
useful for describing a regex string in human readable format.

I can recommend http://www.regular-expressions.info,
http://www.regexbuddy.com and
http://www.regular-expressions.info/cookbook.html

I am not affiliated with any of these sites/books, just a happy customer.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---

I have the following code which should increment the value of the array
$iplist if there is a value there.  When I walk the array at the end,
all the values = 1.  What am i doing wrong?

--Curtis

while (!feof($INPUTFILE))
 {
   $chunks = fgetcsv($INPUTFILE, " ", '"');
   $firstpart = explode(" ", $chunks[0]);
   $ipaddress = $firstpart[0];
   $agent =
$chunks[4];
//   print (stripos($agent, "compatible;
MSIE 6.0; Windows NT 5.1; SV1")."\n");
   if
(stripos($agent, "compatible; MSIE 6.0; Windows NT 5.1; SV1")
> 0)
   {
      
$iplist[$ipaddress]++;
      
//print("$ipaddress\t$agent\n");
   }
   while (list($key, $value) = each($iplist))
   {
    
print("$key\t$value\n");
   }
  }


--- End Message ---

Reply via email to