php-general Digest 2 Oct 2008 10:53:45 -0000 Issue 5714
Topics (messages 281353 through 281358):
Re: SESSION array problems
281353 by: Nathan Rixham
281355 by: Jim Lucas
Re: Questions regarding limits of processes launched bysystem, exec,passthru ...
281354 by: Valentin Schmid - ICSurselva AG
Re: store array into session variable and get it back later
281356 by: Stut
php server push
281357 by: gkrisz.upcmail.hu
281358 by: Nathan Rixham
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 ---
tedd wrote:
At 3:41 PM -0400 10/1/08, tedd wrote:
What about:
foreach ($_SESSION['user_id'] as $key => $value)
{
$last = $_SESSION['last_name'][$key];
$first = $_SESSION['first_name'][$key];
echo "$last, $first";
}
Jay:
Close, it produced:
Array, Array
Array, Array
Array, Array
Cheers,
tedd
My error, if produced.
Cable, Diane
a, i
While print_r($_SESSION); JUST BEFORE IT produced:
[user_id] => Array
(
[0] => 6156
[1] => 7030
[2] => 656
)
[first_name] => Array
(
[0] => Diane
[1] => first name
[2] => Helen
)
[last_name] => Array
(
[0] => Cable
[1] => CagoEsogs-temp (forum)
[2] => Cahalane
)
Now, what wrong with this picture?
Cheers,
tedd
tedd wrote:
> At 3:41 PM -0400 10/1/08, tedd wrote:
>>> What about:
>>>
>>> foreach ($_SESSION['user_id'] as $key => $value)
>>> {
>>> $last = $_SESSION['last_name'][$key];
>>> $first = $_SESSION['first_name'][$key];
>>> echo "$last, $first";
>>> }
>>
>> Jay:
>>
>> Close, it produced:
>>
>> Array, Array
>> Array, Array
>> Array, Array
>>
>> Cheers,
>>
>> tedd
>
>
> My error, if produced.
>
>
> Cable, Diane
> a, i
>
> While print_r($_SESSION); JUST BEFORE IT produced:
>
> [user_id] => Array
> (
> [0] => 6156
> [1] => 7030
> [2] => 656
> )
>
> [first_name] => Array
> (
> [0] => Diane
> [1] => first name
> [2] => Helen
> )
>
> [last_name] => Array
> (
> [0] => Cable
> [1] => CagoEsogs-temp (forum)
> [2] => Cahalane
> )
>
> Now, what wrong with this picture?
>
> Cheers,
>
> tedd
in this case.. what's happened is:
$_SESSION['first_name'] is a reference to a variable $first (or whatever
is in your for loop)
$_SESSION['last_name'] is a reference to a variable $last (or whatever
is in your for loop)
when you've set $last and $first to string's in the for loop it's passed
the variable by reference back to $_SESSION['first_name'] and
$_SESSION['last_name'] as strings;
when it hit's the second iteration on the for loop it now has strings to
deal with so uses the $key (holding integer 1 at this stage) as a string
offset thus giving you the second character (offset [1]) of the string
variables $last/$first. now set to 'cable'/'diane' thus giving you the
'a'/'i'. when it does pass three there is no offset [2] so gives you
nothing.
*phew*
reproduce code!
<?php
$userids = array('6156','1234','8867');
$first = array('Diane','Big','Joe');
$last = array('Cable','Ron','Dirt');
function save_to_session( ) {
global $userids , $first , $last;
$_SESSION['user_id'] = &$userids;
$_SESSION['first_name'] = &$first;
$_SESSION['last_name']= &$last;
}
save_to_session( );
print_r( $_SESSION );
$num_users = count($_SESSION['user_id']);
for ($i = 0; $i < $num_users; $i++) {
$first = $_SESSION['first_name'][$i];
$last = $_SESSION['last_name'][$i];
echo "$last, $first\n";
}
?>
Regards!
--
nathan ( [EMAIL PROTECTED] )
{
Senior Web Developer
php + java + flex + xmpp + xml + ecmascript
web development edinburgh | http://kraya.co.uk/
}
--- End Message ---
--- Begin Message ---
tedd wrote:
Hi gang:
Apparently, there's something going on here that I don't understand --
this happens far too often these days.
Here's a print_r($_SESSION); of the session arrays I'm using:
[user_id] => Array
(
[0] => 6156
[1] => 7030
[2] => 656
)
[first_name] => Array
(
[0] => Diane
[1] => Fred
[2] => Helen
)
[last_name] => Array
(
[0] => Cable
[1] => Cago
[2] => Cahalan
The following is how I tried to access the data contained in the
$_SESSION arrays:
$num_users = count($_SESSION['user_id']);
for ($i = 0; $i < $num_users; $i++)
{
$last_name = $_SESSION['last_name'][$i];
$first_name = $_SESSION['first_name'][$i];
echo("<p>$last_name, $first_name</p>");
}
The only thing that came out correct was the first echo. The remaining
echos had no values for $first_name or $last_name.
What's happening here?
Cheers,
tedd
PS: I'm open to other suggestions as to how to do this.
Why don't you echo what you are trying to access for each loop
for ($i = 0; $i < $num_users; $i++)
{
print_r($_SESSION['last_name'][$i]);
print_r($_SESSION['first_name'][$i]);
}
Does the above return to you what you would expect?
An alternate to what you are doing here would be this.
foreach ( $_SESSION['user_id'] AS $i=>$id)
{
print_r($id);
print_r($_SESSION['last_name'][$i]);
print_r($_SESSION['first_name'][$i]);
}
How about this?
Jim Lucas
--- End Message ---
--- Begin Message ---
Hello Thodoris,
>
>> Hello all again,
>>
>> It seems that Problem can only be solved by one of the following ways:
>>
>> 1. Don't use mod_php; use CGI or FastCGI instead. Then it would be
>> possible to limit the resources via RLimitCPU / RLimitMEM.
>>
>
> I haven't tried that but as I have noticed in the reference that
> probably mod_php's processes get limited too:
>
> This applies to processes forked off from Apache children servicing
> requests, not the Apache children themselves.
> This includes CGI scripts and SSI exec commands, but not any processes
> forked off from the Apache parent such as piped logs.
>
> It says that it includes CGI but it doesn't exclude necessarily mod_php.
> Does it ?
No, it doesn't.
--- End Message ---
--- Begin Message ---
On 1 Oct 2008, at 20:42, Per Jessen wrote:
Stut wrote:
On 1 Oct 2008, at 11:40, Per Jessen wrote:
Alain Roger wrote:
how can i get the 'name' value for each row in this session stored
array ? thx.
You haven't stored an array in the session, you've tried to store an
object of class CBreadcrumb. Which AFAIK isn't supported.
It is supported but you need to be careful about resources in the
class. You can handle these gracefully using the __sleep and __wake
magic methods. You also need to make sure the class has been loaded
before starting the session or have an __autoload defined.
Thanks, I was not aware. Very clear and succinct explanation, btw.
No worries. I find it best to limit myself to responding quickly,
otherwise I get nothing else done! It also forces me to get straight
to the point.
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
Hi, (i hope this is the right place to ask questions like below)
I am trying to use content type 'multipart/x-mixed-replace' to
achive server pushing and I have the following piece of code, which works
perfectly.
/* file.html */
function handleContent(event)
{
var result = event.target.responseXML;
}
var xrequest = new XMLHttpRequest();
xrequest.multipart = true;
xrequest.open("GET","file.php",true);
xrequest.onload = handleContent;
xrequest.send(null);
/* file.php */
<?php
header('Content-type: multipart/x-mixed-replace;boundary="rn9012"');
print "--rn9012\n";
/*
With these prints i can generate an event on the browser side.
For instance if I would like to wait for sg to happen on the server
side i can
make an infinite loop and wait. when sg happens i just print the event.
*/
while (true) {
print "Content-type: application/xml\n\n";
print "<?xml version='1.0'?>\n";
print "<content>event1</content>\n";
print "--rn9012\n";
flush();ob_flush();
}
sleep(5);
/* I close the connection with this event. Closing tag: with 2 extra -- */
print "Content-type: application/xml\n\n";
print "<?xml version='1.0'?>\n";
print "<content>last event</content>\n";
print "--rn9012--\n";
?>
BUT I have to keep an infinite loop on the server side for each clients
just to be able to send and event (let's say in every 3rd hour)
Is there a way with which i can keep the connection without the infinite loop,
and send the event message to the client from a different php file?
/* file2.php */
<?php
/* this is what i wish */
send_event_toclient(clientid, eventmessage);
//clientid: id of the client that i had saved before
//i think this id should be sg socket where i can write the output to.
?>
I hope I cound explain my problem clearly
thank you in advance
Christian Guttmann
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
Hi, (i hope this is the right place to ask questions like below)
I am trying to use content type 'multipart/x-mixed-replace' to
achive server pushing and I have the following piece of code, which works perfectly.
/* file.html */
function handleContent(event)
{
var result = event.target.responseXML;
}
var xrequest = new XMLHttpRequest();
xrequest.multipart = true;
xrequest.open("GET","file.php",true);
xrequest.onload = handleContent;
xrequest.send(null);
/* file.php */
<?php
header('Content-type: multipart/x-mixed-replace;boundary="rn9012"');
print "--rn9012\n";
/*
With these prints i can generate an event on the browser side.
For instance if I would like to wait for sg to happen on the server side i can
make an infinite loop and wait. when sg happens i just print the event.
*/
while (true) {
print "Content-type: application/xml\n\n";
print "<?xml version='1.0'?>\n";
print "<content>event1</content>\n";
print "--rn9012\n";
flush();ob_flush();
}
sleep(5);
/* I close the connection with this event. Closing tag: with 2 extra -- */
print "Content-type: application/xml\n\n";
print "<?xml version='1.0'?>\n";
print "<content>last event</content>\n";
print "--rn9012--\n";
?>
BUT I have to keep an infinite loop on the server side for each clients
just to be able to send and event (let's say in every 3rd hour)
Is there a way with which i can keep the connection without the infinite loop,
and send the event message to the client from a different php file?
/* file2.php */
<?php
/* this is what i wish */
send_event_toclient(clientid, eventmessage);
//clientid: id of the client that i had saved before
//i think this id should be sg socket where i can write the output to.
?>
I hope I cound explain my problem clearly
thank you in advance
Christian Guttmann
ahh an age old problem; in short you need something like "meteor" to
handle this (a different http server); tbh the http protocol isn't cut
out for this.
You may want to save some time and look into XMPP with PUB-SUB; it's
lightweight permanent client server connection with server push (ignite
realtime/jive software do a great XMPP server that's opensource ;)
Regards and sorry for the vagueness - there are tonnes of articles
everywhere on the net documenting the problems; this is why everybody
poll's all the time.
if you do want a strictly PHP resolution then look into making your own
multiprocess daemon with socket stream server / client and the stream_
functions - rather complicated and not a "standard" way fo doing things,
but fun :)
--
nathan ( [EMAIL PROTECTED] )
{
Senior Web Developer
php + java + flex + xmpp + xml + ecmascript
web development edinburgh | http://kraya.co.uk/
}
--- End Message ---