php-general Digest 5 Mar 2012 07:03:40 -0000 Issue 7712

Topics (messages 316865 through 316876):

Re: Weird Behaviour of Array
        316865 by: Ashley Sheridan
        316866 by: Stuart Dallas

Script execution after window close
        316867 by: Nibin V M
        316868 by: Ashley Sheridan
        316869 by: Nibin V M
        316870 by: Govinda
        316871 by: Stuart Dallas
        316872 by: Nibin V M
        316873 by: Govinda
        316874 by: Ashley Sheridan
        316875 by: Nibin V M

Questionnaire on motivation analysis of free open source software and open 
content (final version
        316876 by: George Tsinarakis

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 ---
On Sun, 2012-03-04 at 20:01 +0530, Ruwan Pathmalal wrote:

> 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


I think because $array['12_5'][55] is originally a string, and PHP
allows you to treat them as arrays of characters (like C++) what is
happening is some odd setting of values within the string. This is why
when you unset the value or define it as a blank array it is working as
expected.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 4 Mar 2012, at 14:31, Ruwan Pathmalal wrote:

> 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 :) )

Not a bug. You set $array['12_5'][55] to a string, then you try to use it as an 
array. Strings can be accessed as arrays.

> $array['12_5'][55][45] = '45';

This line sets the 45th character in the string to 4 (each element of a string 
accessed as an array can only contain a single character, so it throws the 5 
away).

> $array['12_5'][55][56] = '76';
> $array['12_5'][55][85] = '85';
> $array['12_5'][55][96] = '96';

Likewise with these. You're not seeing the additional spaces because you're 
viewing it as an HTML page. Run it on the command line or add <pre> before the 
<?php to see the actual value, which is...

"55                                           4          7                      
      8          9"

-Stuart

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

--- End Message ---
--- Begin Message ---
Hello,

I need to run a few commands when a user close the browser tab. That is, I
have a php page ( index.php ) and it will create a temporary file to track
some stuffs. That temporary file should be removed, when the user close the
browser tab. Is there any way to achieve this?

Thank you,

-- 
Regards....

Nibin.

http://TechsWare.in

--- End Message ---
--- Begin Message ---
On Sun, 2012-03-04 at 20:49 +0530, Nibin V M wrote:

> Hello,
> 
> I need to run a few commands when a user close the browser tab. That is, I
> have a php page ( index.php ) and it will create a temporary file to track
> some stuffs. That temporary file should be removed, when the user close the
> browser tab. Is there any way to achieve this?
> 
> Thank you,
> 


Not reliably. There are events in Javascript that you can use to trigger
an Ajax call (such as onbeforeunload and onunload) but these work
slightly differently from browser to browser and may not allow you to
execute anything on the browser if the user is navigating away from the
site or closing the tab/window.

Why can't you use the session for this, and allow the session to expire
after a certain period of inactivity, which would be better than
reinventing what sounds like session behaviour.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
in fact....I really need to remove the file ( which will be created for
every access - making a copy from another location ). I can't leave that
file alone for ever in the user disk space! :(

On Sun, Mar 4, 2012 at 9:01 PM, Ashley Sheridan 
<a...@ashleysheridan.co.uk>wrote:

> **
> On Sun, 2012-03-04 at 20:49 +0530, Nibin V M wrote:
>
> Hello,
>
> I need to run a few commands when a user close the browser tab. That is, I
> have a php page ( index.php ) and it will create a temporary file to track
> some stuffs. That temporary file should be removed, when the user close the
> browser tab. Is there any way to achieve this?
>
> Thank you,
>
>
>
> Not reliably. There are events in Javascript that you can use to trigger
> an Ajax call (such as onbeforeunload and onunload) but these work slightly
> differently from browser to browser and may not allow you to execute
> anything on the browser if the user is navigating away from the site or
> closing the tab/window.
>
> Why can't you use the session for this, and allow the session to expire
> after a certain period of inactivity, which would be better than
> reinventing what sounds like session behaviour.
>
>   --
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


-- 
Regards....

Nibin.

http://TechsWare.in

--- End Message ---
--- Begin Message ---
> in fact....I really need to remove the file ( which will be created for
> every access - making a copy from another location ). I can't leave that
> file alone for ever in the user disk space! :(

Fine, so delete it after a period of inactivity

--- End Message ---
--- Begin Message ---
On 4 Mar 2012, at 15:31, Nibin V M wrote:

> in fact....I really need to remove the file ( which will be created for
> every access - making a copy from another location ). I can't leave that
> file alone for ever in the user disk space! :(

Ash is right in that this is exactly what sessions are used for, so unless the 
data you are storing for the user is fairly large you'd be better off using 
them: http://php.net/session

Why do you need to copy the file? Might be an idea to describe what you're 
actually doing rather than focus on this particular part. Do you make changes 
to the file after you've copied it? If not, why not use the original copy? If 
you do modify is, how and why? I'll bet there's a better way to do what you're 
doing.

If you absolutely need to make these copies, your best bet is to have a script 
executed by cron periodically to clean up files with a last modified timestamp 
older than n seconds, and make sure each page request calls the touch function 
for that user's file to updated the file's timestamp.

-Stuart

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

> On Sun, Mar 4, 2012 at 9:01 PM, Ashley Sheridan 
> <a...@ashleysheridan.co.uk>wrote:
> 
>> **
>> On Sun, 2012-03-04 at 20:49 +0530, Nibin V M wrote:
>> 
>> Hello,
>> 
>> I need to run a few commands when a user close the browser tab. That is, I
>> have a php page ( index.php ) and it will create a temporary file to track
>> some stuffs. That temporary file should be removed, when the user close the
>> browser tab. Is there any way to achieve this?
>> 
>> Thank you,
>> 
>> 
>> 
>> Not reliably. There are events in Javascript that you can use to trigger
>> an Ajax call (such as onbeforeunload and onunload) but these work slightly
>> differently from browser to browser and may not allow you to execute
>> anything on the browser if the user is navigating away from the site or
>> closing the tab/window.
>> 
>> Why can't you use the session for this, and allow the session to expire
>> after a certain period of inactivity, which would be better than
>> reinventing what sounds like session behaviour.
>> 
>>  --
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>> 
>> 
>> 
> 
> 
> -- 
> Regards....
> 
> Nibin.
> 
> http://TechsWare.in


--- End Message ---
--- Begin Message ---
ok..I have script which will run based on  some values  in "user's"
homedir. In fact I have tried to run the script from a various locations;
but it didn't work as expected like it run from each users homedir. So,
when the user access the page, it will copy the actual script to the user's
homedir and executes it. I don't want to leave it there for ever; so I have
to remove it from there when the user close the browser ( or after a period
of in activity ). But I don't know how to code it :(

On Sun, Mar 4, 2012 at 9:08 PM, Govinda <govinda.webdnat...@gmail.com>wrote:

>
> > in fact....I really need to remove the file ( which will be created for
> > every access - making a copy from another location ). I can't leave that
> > file alone for ever in the user disk space! :(
>
> Fine, so delete it after a period of inactivity
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Regards....

Nibin.

http://TechsWare.in

--- End Message ---
--- Begin Message ---
>>> in fact....I really need to remove the file ( which will be created for
>>> every access - making a copy from another location ). I can't leave that
>>> file alone for ever in the user disk space! :(
>> 
>> Fine, so delete it after a period of inactivity
> 
> ok..I have script which will run based on  some values  in "user's" homedir. 
> In fact I have tried to run the script from a various locations; but it 
> didn't work as expected like it run from each users homedir. So, when the 
> user access the page, it will copy the actual script to the user's homedir 
> and executes it. I don't want to leave it there for ever; so I have to remove 
> it from there when the user close the browser ( or after a period of in 
> activity ). But I don't know how to code it :( 

My suggestion is to sort out the real issue, rather than try to "fix it" with 
the workaround of copying that file to "each user's homedir".  It sounds like 
you are just adding unnecessary complexity to your work.  

Maybe make a new post/thread where you describe THAT issue very carefully.. and 
what you have tried that is not working the way you thought it should.  So far 
it is not clear enough to me anyway - to help.  But that could be because of my 
shortcomings more than your post's shortcoming; I am not expert on many topics 
covered on this list, especially in the area of managing your webserver.

-Govinda

--- End Message ---
--- Begin Message ---
On Sun, 2012-03-04 at 11:29 -0500, Govinda wrote:

> >>> in fact....I really need to remove the file ( which will be created for
> >>> every access - making a copy from another location ). I can't leave that
> >>> file alone for ever in the user disk space! :(
> >> 
> >> Fine, so delete it after a period of inactivity
> > 
> > ok..I have script which will run based on  some values  in "user's" 
> > homedir. In fact I have tried to run the script from a various locations; 
> > but it didn't work as expected like it run from each users homedir. So, 
> > when the user access the page, it will copy the actual script to the user's 
> > homedir and executes it. I don't want to leave it there for ever; so I have 
> > to remove it from there when the user close the browser ( or after a period 
> > of in activity ). But I don't know how to code it :( 
> 
> My suggestion is to sort out the real issue, rather than try to "fix it" with 
> the workaround of copying that file to "each user's homedir".  It sounds like 
> you are just adding unnecessary complexity to your work.  
> 
> Maybe make a new post/thread where you describe THAT issue very carefully.. 
> and what you have tried that is not working the way you thought it should.  
> So far it is not clear enough to me anyway - to help.  But that could be 
> because of my shortcomings more than your post's shortcoming; I am not expert 
> on many topics covered on this list, especially in the area of managing your 
> webserver.
> 
> -Govinda


To add to what Govinda said, the real problem does indeed seem to be
that you're using this hack in order to make your code work, and sorting
that would be far more beneficial to you in the long run.

On first thoughts, it sounds like a path issue somewhere. If the script
isn't run as the user but is just run as the same user from different
users directories, then it's probably not a problem with the PATH
environment variable (assuming your secondary script is some kind of
Bash script). Let's see what you're doing with that and see if we can
help.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
ok..thanks guys...I will check further then. thanks for your inputs :)

On Sun, Mar 4, 2012 at 9:59 PM, Govinda <govinda.webdnat...@gmail.com>wrote:

> >>> in fact....I really need to remove the file ( which will be created for
> >>> every access - making a copy from another location ). I can't leave
> that
> >>> file alone for ever in the user disk space! :(
> >>
> >> Fine, so delete it after a period of inactivity
> >
> > ok..I have script which will run based on  some values  in "user's"
> homedir. In fact I have tried to run the script from a various locations;
> but it didn't work as expected like it run from each users homedir. So,
> when the user access the page, it will copy the actual script to the user's
> homedir and executes it. I don't want to leave it there for ever; so I have
> to remove it from there when the user close the browser ( or after a period
> of in activity ). But I don't know how to code it :(
>
> My suggestion is to sort out the real issue, rather than try to "fix it"
> with the workaround of copying that file to "each user's homedir".  It
> sounds like you are just adding unnecessary complexity to your work.
>
> Maybe make a new post/thread where you describe THAT issue very
> carefully.. and what you have tried that is not working the way you thought
> it should.  So far it is not clear enough to me anyway - to help.  But that
> could be because of my shortcomings more than your post's shortcoming; I am
> not expert on many topics covered on this list, especially in the area of
> managing your webserver.
>
> -Govinda
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Regards....

Nibin.

http://TechsWare.in

--- End Message ---
--- Begin Message ---
Dear community members,

We are researchers in Technical University of Crete and our current
research
is in the field of motivation analysis of free open source and open content
software projects participants. Some time ago we send to the list a link
for
the questionnaire we created, but as many community members had asked us
we have created an updated version at open office. We would like to ask you
to fill the attached
questionnaire and send it back to us with e-mail in my address (
gtsinara...@isc.tuc.gr),
and also forward it to other  people involved in such teams and projects.

All personal information will be kept confidential and will be used for
academic purposes only. For further information, suggestions and comments
please
do not hesitate to contact with us.



Thank you in advance

Dr G. Tsinarakis

-- 
-------------------------------------------------------
Dr. George Tsinarakis
Production and Management Engineer,
CAM Laboratory
Department of Production Engineering and Management
Technical University of Crete
University Campus, 73 100 Chania,
Crete, Greece
Tel: +30 2821 037306
Fax: +30 2821 037551
E-mail: tsi...@dpem.tuc.gr
-------------------------------------------------------

Attachment: questionaire.odt
Description: application/vnd.oasis.opendocument.text


--- End Message ---

Reply via email to