php-general Digest 4 Mar 2012 14:31:08 -0000 Issue 7711

Topics (messages 316851 through 316864):

Re: Nested database loops and completing an unordered list....
        316851 by: Jay Blanchard

SESSION var and Objects problem
        316852 by: Jim Giner
        316853 by: Stuart Dallas
        316854 by: Jim Giner
        316855 by: Stuart Dallas
        316856 by: Jim Giner
        316857 by: Stuart Dallas
        316858 by: Jim Giner
        316860 by: Simon Schick

Re: problem about PHP-FPM in TCP socket and Unix socket
        316859 by: Daniel Fenn
        316862 by: Matijn Woudt
        316863 by: Daniel Fenn

Re: curl equivalent in PHP
        316861 by: Matijn Woudt

Weird Behaviour of Array
        316864 by: Ruwan Pathmalal

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
[snip]
> I'm not saying you should get rid of the recursive function calls, but 
> rather, why not pull all your data in one SQL call, then use recursive 
> functions on the returned array of data.  It will save a little time by not 
> hitting the DB on each function call too.
> [/snip]

I'll just need to wrap my head around using a recursive function to iterate 
through the array.

--- End Message ---
--- Begin Message ---
My first foray into classes & objects.

When retrieving a set of records, I'm using a class to build an object.  At 
this time I save each record/object into a Session array by doing this:

$rows = mysql_num_rows($qrslts);
 if ($rows > 0)
  for ($i=1;$i<=$rows;$i++)
  {
       $row = mysql_fetch_array($qrslts);
       $e = new Entry;
       if ($e->GetAnEntry($row['recordkey'],$row['Eventcode']))
       {
            $evts[] = $e;
            array_push($_SESSION['TMScurr_evts'],$e);     // THIS DOESN'T
            $cls_errs .= " Stored $e->event in sess var $i-1; ";   // THIS 
WORKS
       }
       else
            $cls_errs .= "Could not retrieve event record for 
".$row['recordkey']." ".$row['Eventcode'];
  }

The above code works AFAIK - the line above the array_push correctly stores 
my retreived record data  in the $evts array just fine and I can see the 
data when I use that array to display my page.
Note also that the var $cls_errs following the array_push does show me that 
valid values are being stored in $e
Later on, in my main process I attempt to retreive the contents of my 
Session var to use to re-display the data.  The code for that doesn't 
display any values.  In trying to debug this here is what I've done:

$cnt = count($_SESSION['TMScurr_evts']);
 echo "In Display  process with $cnt recs in session var TMScurr_evts. "; 
// THIS WORKS
 reset($_SESSION['TMScurr_evts']);
 $e = new Entry;
 for ($i=0;$i<count($_SESSION['TMScurr_evts']);$i++)
 {
      $e = array_pop($_SESSION['TMScurr_evts']);
      echo " in Display process - sess event $i is $e->event<br>";    // 
THIS DOESN'T
 }

This debugging code correctly tells me how many entries are in the Session 
array variable, but the attempt to echo the values stored in the first field 
of each object contained in it shows blank for each one.

What am I doing wrong when I try to pull the contents of my session array 
out and store them back into an Entry object, one at a time, so that I can 
display the object on my webpage?? 



--- End Message ---
--- Begin Message ---
On 2 Mar 2012, at 20:07, Jim Giner wrote:

> My first foray into classes & objects.
> 
> When retrieving a set of records, I'm using a class to build an object.  At 
> this time I save each record/object into a Session array by doing this:
> 
> $rows = mysql_num_rows($qrslts);
> if ($rows > 0)
>  for ($i=1;$i<=$rows;$i++)
>  {
>       $row = mysql_fetch_array($qrslts);
>       $e = new Entry;
>       if ($e->GetAnEntry($row['recordkey'],$row['Eventcode']))
>       {
>            $evts[] = $e;
>            array_push($_SESSION['TMScurr_evts'],$e);     // THIS DOESN'T
>            $cls_errs .= " Stored $e->event in sess var $i-1; ";   // THIS 
> WORKS
>       }
>       else
>            $cls_errs .= "Could not retrieve event record for 
> ".$row['recordkey']." ".$row['Eventcode'];
>  }

What is the type of $e (i.e. what's the class called)?

Side note... it looks like GetAnEntry fetches the entry into internal data. 
This isn't really how objects are supposed to work. To be more OO-like you 
should be passing the recordkey and Eventcode values into the constructor. But 
that's not relevant to your issue.

> The above code works AFAIK - the line above the array_push correctly stores 
> my retreived record data  in the $evts array just fine and I can see the 
> data when I use that array to display my page.
> Note also that the var $cls_errs following the array_push does show me that 
> valid values are being stored in $e
> Later on, in my main process I attempt to retreive the contents of my 
> Session var to use to re-display the data.  The code for that doesn't 
> display any values.  In trying to debug this here is what I've done:
> 
> $cnt = count($_SESSION['TMScurr_evts']);
> echo "In Display  process with $cnt recs in session var TMScurr_evts. "; 
> // THIS WORKS
> reset($_SESSION['TMScurr_evts']);
> $e = new Entry;
> for ($i=0;$i<count($_SESSION['TMScurr_evts']);$i++)
> {
>      $e = array_pop($_SESSION['TMScurr_evts']);
>      echo " in Display process - sess event $i is $e->event<br>";    // 
> THIS DOESN'T
> }
> 
> This debugging code correctly tells me how many entries are in the Session 
> array variable, but the attempt to echo the values stored in the first field 
> of each object contained in it shows blank for each one.
> 
> What am I doing wrong when I try to pull the contents of my session array 
> out and store them back into an Entry object, one at a time, so that I can 
> display the object on my webpage?? 

In the above script, the one that gets the objects out of the session, has the 
class been declared? IOW, have you included the PHP file that defines that 
class? If not then it won't be able to recreate the object.

If that was the problem then I suggest you make sure you have error_reporting 
set to at least E_ALL, and display_errors set on, because this issue will be 
causing a fatal error, the text of which would make it obvious what's going 
wrong.

-Stuart

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

--- End Message ---
--- Begin Message --- Yes I ahve the class defined. The classes work in most cases - just this one place where I want to save the objects in a sess var for re-use fails me.


--- End Message ---
--- Begin Message ---
Please quote the pertinent bit of the message you're replying to, it makes 
using the list a halluvalot easier and improves SEO for the archives.

On 2 Mar 2012, at 20:55, Jim Giner wrote:

> Yes I ahve the class defined.  The classes work in most cases - just this one 
> place where I want to save the objects in a sess var for re-use fails me.

Put the following line at the top of the code that you posted and post the 
output.

echo '<pre>'; var_dump($_SESSION['TMScurr_evts']); die('</pre>');

Have you checked your error log, or your error settings? Scripts generally 
don't stop executing for no reason or without saying why.

-Stuart

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

--- End Message ---
--- Begin Message ---
ok - In examinig the objects in the Session after the data has been 
displayed and the user has hit triggered a re-entry into my script (just one 
script involved here), the objects in the session array now say 
"[__PHP_Incomplete_Class_Name" and "__PHP_Incomplete_Class Object ".  They 
didn't say that during my examiniation of the sess var before exiting the 
script.

Also with All error reporting on (a great tip that I never think of) I get 
many messages indicating that the object may not have been loaded.  I don't 
know what this means.  The include file for my class is present in my script 
and is always loaded.  But at this point in the process no functions of the 
class have been called.  Is that a problem?  In trying to re-display my data 
stored in the Sessioin array I instantiate a var of the class and then pop 
an array off the session var and assign it to the object and then call my 
display function to show the data on the webpage - that is where I get the 
errors.  Here is one of these messages:

  Notice: DisplayAnEntry() [function.displayanentry]: The script tried to 
execute a method or access a property of an incomplete object. Please ensure 
that the class definition "Entry" of the object you are trying to operate on 
was loaded _before_ unserialize() gets called or provide a __autoload() 
function to load the class definition in 
/home/albany/public_html/tms/php/tmsentry.php on line 372

 



--- End Message ---
--- Begin Message ---
On 2 Mar 2012, at 21:09, Jim Giner wrote:

> ok - In examinig the objects in the Session after the data has been 
> displayed and the user has hit triggered a re-entry into my script (just one 
> script involved here), the objects in the session array now say 
> "[__PHP_Incomplete_Class_Name" and "__PHP_Incomplete_Class Object ".  They 
> didn't say that during my examiniation of the sess var before exiting the 
> script.
> 
> Also with All error reporting on (a great tip that I never think of) I get 
> many messages indicating that the object may not have been loaded.  I don't 
> know what this means.  The include file for my class is present in my script 
> and is always loaded.  But at this point in the process no functions of the 
> class have been called.  Is that a problem?  In trying to re-display my data 
> stored in the Sessioin array I instantiate a var of the class and then pop 
> an array off the session var and assign it to the object and then call my 
> display function to show the data on the webpage - that is where I get the 
> errors.  Here is one of these messages:
> 
>  Notice: DisplayAnEntry() [function.displayanentry]: The script tried to 
> execute a method or access a property of an incomplete object. Please ensure 
> that the class definition "Entry" of the object you are trying to operate on 
> was loaded _before_ unserialize() gets called or provide a __autoload() 
> function to load the class definition in 
> /home/albany/public_html/tms/php/tmsentry.php on line 372

Make sure the class is declared before you call session_start.

-Stuart

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

--- End Message ---
--- Begin Message ---
"Stuart Dallas" <stu...@3ft9.com> wrote in message 
news:7eeba658-c7f6-4449-87bd-aac71b41e...@3ft9.com...

Make sure the class is declared before you call session_start.
*****

You Da Man!!

I see now why it makes a difference.  The session tries to bring back the 
data but doesn't know how to handle the objects in the session vars since 
the objects haven't been defined.  Never would of thought of that!

Thank you for being there!  :) 



--- End Message ---
--- Begin Message ---
Hi, Jim

To avoid this kind of problem it would also help to provide an
autoloader-function as PHP then tries to load the class-definition by this
autoloader ;)
Using that you'd bind yourself to have a pretty good system for php-classes
and you'd avoid having problems like that.

I'd in fact have never thought about a solution like that - but that may
comes from the fact that I always use auto-loader-scripts ;)

One additional info:
I had some problems putting an instance of *SimpleXmlElement *into the
session ... The only valuable info I found was this error:
*Fatal error: Exception thrown without a stack frame in Unknown on line 0*

Here's the solution and description why:
http://stackoverflow.com/questions/4624223/object-in-session-fatal-error-exception-thrown-without-a-stack-frame-in-unknow#answer-4624256

Bye
Simon

2012/3/2 Jim Giner <jim.gi...@albanyhandball.com>

> "Stuart Dallas" <stu...@3ft9.com> wrote in message
> news:7eeba658-c7f6-4449-87bd-aac71b41e...@3ft9.com...
>
> Make sure the class is declared before you call session_start.
> *****
>
> You Da Man!!
>
> I see now why it makes a difference.  The session tries to bring back the
> data but doesn't know how to handle the objects in the session vars since
> the objects haven't been defined.  Never would of thought of that!
>
> Thank you for being there!  :)
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
This how I would look at it, if it on the same box use socket, and yes
it is expected that socket is faster than TCP since (as far as I know)
you don't need to deal with the overhead of TCP.

Regards,
Daniel Fenn







On Sat, Mar 3, 2012 at 3:56 AM, Yuchen Wang <phob...@gmail.com> wrote:
> Hello all,
>
> I am trying to config some new server
>
> All of my servers are using TCP Socket(127.0.0.1:9000) between nginx and
> php-fpm before
>
> But, I run ab(ab -n 20000 -c50 http://192.168.74.130:81/) to test the
> performance of Unix Socket and TCP Socket,
> the result is Unix is little better than TCP
>
> Usually we run php and web server in the same server,
> So, TCP socket and Unix socket
> Which method do you prefer ?
>
> Thank you
>
> --
> *Yuchen Wang*

--- End Message ---
--- Begin Message ---
On Fri, Mar 2, 2012 at 5:56 PM, Yuchen Wang <phob...@gmail.com> wrote:
> Hello all,
>
> I am trying to config some new server
>
> All of my servers are using TCP Socket(127.0.0.1:9000) between nginx and
> php-fpm before
>
> But, I run ab(ab -n 20000 -c50 http://192.168.74.130:81/) to test the
> performance of Unix Socket and TCP Socket,
> the result is Unix is little better than TCP
>
> Usually we run php and web server in the same server,
> So, TCP socket and Unix socket
> Which method do you prefer ?
>
> Thank you
>
> --
> *Yuchen Wang*

Always go for Unix sockets. TCP has quite a bit overhead which
includes stuff you really don't need if two processes live on the same
server. Think about error detection, flow control, congestion control,
packet loss. None of these are needed if your system is functioning
correctly.

- Matijn

--- End Message ---
--- Begin Message ---
Something else that should be said: You won't need to muck around with
firewall settings as well (that if your running a firewall on the same
box





On Sat, Mar 3, 2012 at 11:22 AM, Matijn Woudt <tijn...@gmail.com> wrote:
> On Fri, Mar 2, 2012 at 5:56 PM, Yuchen Wang <phob...@gmail.com> wrote:
>> Hello all,
>>
>> I am trying to config some new server
>>
>> All of my servers are using TCP Socket(127.0.0.1:9000) between nginx and
>> php-fpm before
>>
>> But, I run ab(ab -n 20000 -c50 http://192.168.74.130:81/) to test the
>> performance of Unix Socket and TCP Socket,
>> the result is Unix is little better than TCP
>>
>> Usually we run php and web server in the same server,
>> So, TCP socket and Unix socket
>> Which method do you prefer ?
>>
>> Thank you
>>
>> --
>> *Yuchen Wang*
>
> Always go for Unix sockets. TCP has quite a bit overhead which
> includes stuff you really don't need if two processes live on the same
> server. Think about error detection, flow control, congestion control,
> packet loss. None of these are needed if your system is functioning
> correctly.
>
> - Matijn
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
On Fri, Mar 2, 2012 at 6:09 PM, Nibin V M <nibi...@gmail.com> wrote:
> Hmm..I am a php newbie ( just started learning it )...
>
> what my need is to display website from my server always for a
> non-registered domain.This is the code I use now to display the website
>
> <?php
> $opts = array(
>  'http'=>array(
>    'method'=>"GET",
>    'header'=>"Accept-language: en\r\n" .
>              "Cookie: foo=bar\r\n"
>  )
> );
>
> $context = stream_context_create($opts);
>
> $fp = fopen('http://www.blahblah.com', 'r', false, $context);
> fpassthru($fp);
> fclose($fp);
> ?>
>
> Of course blahblah.com isn't registered yet. This will load the index page
> of blahblah.com fine ( since I use hosts file to resolve blahblah.com on
> the server ). But if we click on any link, it will give "server not found"
> error since my "local machine" is trying to resolve blahblah.com this time.
> I need to avoid it and want to load my domain "always" from the server when
> I click any link on the webpage, etc .
>
> How can I modify the above code to make it work! If possible, I request
> somebody to tell me the exact code that I need to change in the above
> script - since most of the php part is still greek to me :)
>
> Thank you,

Have you actually read/tried Daniel Browns reply?

The following seems to be all you need...

<?php
echo str_replace('blahblah.com','localhost',file_get_contents('blahblah.com'));
?>

--- End Message ---
--- Begin Message ---
Hi People,
I confused with weird behaviour of array. Following is my script.

<?php
$array = array(
            '12_1'=>array(
                    56=>array(
                            23=>'23',
                            33=>'33')
                    ),
        '12_5'=>array(
                    55=>'55'
            )
        );

$array['12_5'][55][45] = '45';
$array['12_5'][55][56] = '76';
$array['12_5'][55][85] = '85';
$array['12_5'][55][96] = '96';
print_r($array);
?>

Output is -:
Array ( [12_1] => Array ( [56] => Array ( [23] => 23 [33] => 33 ) ) [12_5]
=> Array ( [55] => 55 4 7 8 9 ) )

Sometime this is because, first time $array['12_5'][55] not an array. I
assigned value to it like array. (I suppose overwrite key and then assign
given value as key value pair). See this part of output [12_5] => Array (
[55] => 55 4 7 8 9 ). It compose 4 from 45, 7 from 76, 8 from 85 like that
(first digit of assigned values).

I manage to overcome this problem by unsettling  $array['12_5'][55] before
assigning value to it.

But I want to know why this happening or is this PHP bug ? (Clear
explanation for situation :) )

Thanks
Ruwan

--- End Message ---

Reply via email to