php-general Digest 3 Apr 2012 06:13:26 -0000 Issue 7758

Topics (messages 317428 through 317435):

Re: Thinking out loud - a continuation...
        317428 by: Jay Blanchard
        317429 by: Matijn Woudt
        317430 by: Robert Cummings

Re: Could apc_fetch return a pointer to data in shared memory ?
        317431 by: Stuart Dallas
        317435 by: Simon

Re: Variable representation
        317432 by: tamouse mailing lists

Adding Rows In PHPMYADMIN
        317433 by: Karl James
        317434 by: Tommy Pham

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]
>> function getTiersJson( $company )
>> {
>>    $tiers = getTiers( $company );
>>    $json = JSON_encode( $tiers );
>> }
>> 
>> $tiersJson = getTiersJson( 1 );
>> 
>> ?>
>> 
>> This will output JSON with the following structure:
>> 
[/snip]

OK, now I know I am being dense - but don't I have to add return $json; to 
getTiersJson() ?

--- End Message ---
--- Begin Message ---
On Mon, Apr 2, 2012 at 10:36 PM, Jay Blanchard
<jay.blanch...@sigmaphinothing.org> wrote:
> [snip]
>>> function getTiersJson( $company )
>>> {
>>>    $tiers = getTiers( $company );
>>>    $json = JSON_encode( $tiers );
>>> }
>>>
>>> $tiersJson = getTiersJson( 1 );
>>>
>>> ?>
>>>
>>> This will output JSON with the following structure:
>>>
> [/snip]
>
> OK, now I know I am being dense - but don't I have to add return $json; to 
> getTiersJson() ?

Of course ;)

--- End Message ---
--- Begin Message ---
On 12-04-02 04:36 PM, Jay Blanchard wrote:
[snip]
function getTiersJson( $company )
{
    $tiers = getTiers( $company );
    $json = JSON_encode( $tiers );
}

$tiersJson = getTiersJson( 1 );

?>

This will output JSON with the following structure:

[/snip]

OK, now I know I am being dense - but don't I have to add return $json; to 
getTiersJson() ?

yeah, *lol* in my testing I had a print_r() in the getTiersJson() so didn't notice I wasn't returning since I didn't do anything with the captured value (null without a proper return).

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On 2 Apr 2012, at 15:37, Simon wrote:

> On 2 April 2012 14:27, Stuart Dallas <stu...@3ft9.com> wrote:
>> On 2 Apr 2012, at 14:12, Simon wrote:
>> 
>> > Thanks Maciek
>> >
>> > On 2 April 2012 10:37, Maciek Sokolewicz 
>> > <maciek.sokolew...@gmail.com>wrote:
>> >
>> >> On 02-04-2012 10:12, Simon wrote:
>> >>
>> >>> Thanks Simon. you got my hopes up there for a second.
>> >>>
>> >>> From the php docs page:
>> >>>
>> >>> Critics further argue that it is pointless to use a Singleton in a Shared
>> >>>>
>> >>> Nothing Architecture like PHP where objects are unique>within the Request
>> >>> only anyways.
>> >>>
>> >>> I want the the singleton class to be global to the entire application (ie
>> >>> shared "by reference" across all requests). I'd agree with the above
>> >>> critics that if you have to instantiate your singleton for each request,
>> >>> it's rather pointless.
>> >>>
>> >>> Well, that's simply not possible due to the "shared nothing paradigm".
>> >> If you want to share, you need to either share it via another medium (such
>> >> as a database, as has been suggested a dozen times already) or switch to a
>> >> different language.
>> >
>> >
>> >
>> >> PHP is based on this paradigm, and you should not expect of it to violate
>> >> it just because you want to do things a certain way, which is not the PHP
>> >> way.
>> >>
>> >
>> > The existence of memcached, shm and apc_fetch tell me that PHP already
>> > accepts the need for sharing data between processes. All I'm arguing for is
>> > the ability to share the data by reference rather than by copy.
>> 
>> 
>> As already mentioned several times the closest you will get is shared memory 
>> (as used by APC), but you can't access that by reference because shared 
>> read/write resources need controlled access for stability.
> 
> I know. I understand that (and the issues with locking that might arise if 
> truly shared memory was available).
> 
>> I can't find any material that explains how the .net framework implements 
>> application variables. You mentioned earlier that you *know* that when you 
>> access them you do so by reference. Do you have a source for this knowledge 
>> or is it some sort of sixth sense?
> 
> Source: 10+ years as an ASP and ASP.NET developer. 

Wow. As knowledge goes that's up there with "I believe it therefore it is."

> Having looked for documentation, I agree, it's utterly terrible. It's as if 
> even Microsoft themselves don't fully understand the advantages that 
> application variables give them over the competition. (Though they're hardly 
> likely to be forthcoming about helping others implement similar features).
> 
> Here's some stuff I did find:
> 
> http://www.codeproject.com/Articles/87316/A-walkthrough-to-Application-State#e
> This article explains basically how application variables work. It doesn't 
> specifically mention passing by reference but it discusses thread safety at 
> some length so you might infer that implies passing by reference.

"can cause performance overhead if it is heavy"

And you want to store petabytes of data in there. Smart.

Anyway, that page says nothing about whether it's accessed by reference. It 
implies that writes are atomic, which in turn implies that there is something 
in the background controlling write access to the data.

As for reading the data being done via references there is nothing in that 
article to suggest that.

> http://msdn.microsoft.com/en-us/library/ff650849.aspx
> Here is a more technical discussion about the singleton class is implemented 
> in .NET. Application variables are provided by an instance of a singleton 
> class (the HttpApplication class).

Looks no different to the way you'd implement a singleton in PHP (as expected - 
as a concept it doesn't generally change between languages). Just because the 
HttpApplication class is a singleton doesn't mean that when you request data 
from it you get it by reference.

> http://stackoverflow.com/questions/1132373/do-asp-net-application-variables-pass-by-reference-or-value
> Stack overflow question from someone actually wanting to get a *copy* of an 
> application variable rather than a reference.

According to that page scalar values are returned by value, objects are 
returned as a copy of the reference. Based on that, it would appear that you 
are correct as far as objects are concerned. However, the advice given on 
several pages I've found, including at least one that you've specified, is to 
use application variables lightly and sparingly. It's not something that should 
be used for petabytes of data, mainly because it's all STORED IN MEMORY.

> So, if you read enough of this stuff, you'll find out that a .NET website (an 
> IIS application in MS parlance) runs in a multi-threaded single process. 
> Application variables (and singleton classes) are shared by reference between 
> all threads. It is possible to run an IIS application over multiple processes 
> (to take advantage of multiple processors / server farms for example) but 
> then the Application variables are not shared at all. (This is then pretty 
> comparable to the situation with node.js except that node is not 
> multi-threaded)

Single process. Yes. Precisely. PHP *DOES NOT WORK LIKE THIS* and probably 
never will, therefore it's not comparable. And why do you insist on comparing 
anything with Node.js? Node is specifically single-process and, as far as the 
JS developer is concerned, single-threaded. Node can't share data across 
processes in the same way PHP can't. They're also completely different 
architectures... Node implements the web server within the Node process, PHP 
does not. It's not logical to say that an apple should be like an orange.

I don't understand why we're still talking about this. The architecture of PHP 
does not make sharing data by reference possible, regardless of whether that's 
how ASP.net works. It's irrelevant and frankly I couldn't care less (which I 
think I've mentioned before). I used to use ASP and ASP.net, so I am familiar 
with application variables, but I've never missed them since moving on to other 
technologies. This could be related to the fact that when I moved away from ASP 
I also moved on to far higher levels of traffic than I had ever dealt with 
before.

You said that memcached was slow compared to the .net application variables; of 
this I have no doubt. But again, that's irrelevant. The .net application 
variables cannot scale beyond a single process; memcached can comfortably scale 
to many thousands of servers and beyond.

I use a combination of generated PHP files (for things that don't change one 
the app is running), memcached (for things that do), and many other 
technologies to build web applications that serve many millions of users every 
day, and I have no complaints. Per-process (or even per-server) application 
variables never cross my mind - they just don't provide any significant benefit.

If you want PHP to work the way .net works, modify PHP yourself or pay someone 
to do it for you, because I practically guarantee that you'll find next to no 
support for moving away from the shared-nothing architecture of the PHP core.

Alternatively... stick to ASP.net.

I'm done.

-Stuart

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

--- End Message ---
--- Begin Message ---
On 2 April 2012 22:25, Stuart Dallas <stu...@3ft9.com> wrote:

> On 2 Apr 2012, at 15:37, Simon wrote:
>
> > On 2 April 2012 14:27, Stuart Dallas <stu...@3ft9.com> wrote:
> >> On 2 Apr 2012, at 14:12, Simon wrote:
> >>
> >> > Thanks Maciek
> >> >
> >> > On 2 April 2012 10:37, Maciek Sokolewicz <maciek.sokolew...@gmail.com
> >wrote:
> >> >
> >> >> On 02-04-2012 10:12, Simon wrote:
> >> >>
> >> >>> Thanks Simon. you got my hopes up there for a second.
> >> >>>
> >> >>> From the php docs page:
> >> >>>
> >> >>> Critics further argue that it is pointless to use a Singleton in a
> Shared
> >> >>>>
> >> >>> Nothing Architecture like PHP where objects are unique>within the
> Request
> >> >>> only anyways.
> >> >>>
> >> >>> I want the the singleton class to be global to the entire
> application (ie
> >> >>> shared "by reference" across all requests). I'd agree with the above
> >> >>> critics that if you have to instantiate your singleton for each
> request,
> >> >>> it's rather pointless.
> >> >>>
> >> >>> Well, that's simply not possible due to the "shared nothing
> paradigm".
> >> >> If you want to share, you need to either share it via another medium
> (such
> >> >> as a database, as has been suggested a dozen times already) or
> switch to a
> >> >> different language.
> >> >
> >> >
> >> >
> >> >> PHP is based on this paradigm, and you should not expect of it to
> violate
> >> >> it just because you want to do things a certain way, which is not
> the PHP
> >> >> way.
> >> >>
> >> >
> >> > The existence of memcached, shm and apc_fetch tell me that PHP already
> >> > accepts the need for sharing data between processes. All I'm arguing
> for is
> >> > the ability to share the data by reference rather than by copy.
> >>
> >>
> >> As already mentioned several times the closest you will get is shared
> memory (as used by APC), but you can't access that by reference because
> shared read/write resources need controlled access for stability.
> >
> > I know. I understand that (and the issues with locking that might arise
> if truly shared memory was available).
> >
> >> I can't find any material that explains how the .net framework
> implements application variables. You mentioned earlier that you *know*
> that when you access them you do so by reference. Do you have a source for
> this knowledge or is it some sort of sixth sense?
> >
> > Source: 10+ years as an ASP and ASP.NET developer.
>
> Wow. As knowledge goes that's up there with "I believe it therefore it is."
>

I don't understand your point.


>
> > Having looked for documentation, I agree, it's utterly terrible. It's as
> if even Microsoft themselves don't fully understand the advantages that
> application variables give them over the competition. (Though they're
> hardly likely to be forthcoming about helping others implement similar
> features).
> >
> > Here's some stuff I did find:
> >
> >
> http://www.codeproject.com/Articles/87316/A-walkthrough-to-Application-State#e
> > This article explains basically how application variables work. It
> doesn't specifically mention passing by reference but it discusses thread
> safety at some length so you might infer that implies passing by reference.
>
> "can cause performance overhead if it is heavy"
>

You certainly have to be careful how you use it (as you do any tool).

| And you want to store petabytes of data in there. Smart.

No, I want to store 50 - 200Mb.
At some point in the somewhat distant future I can imagine larger amounts
of shared storage between required. Up to and including petabytes of data
when such large amounts of RAM become practical.

This does not have to cause overhead. The author was suggesting caution to
protect people who aren't sure what they're doing. This can be done with
"no" performance overhead (so long as you have the physical RAM).


>
> Anyway, that page says nothing about whether it's accessed by reference.
> It implies that writes are atomic, which in turn implies that there is
> something in the background controlling write access to the data.
>
> As for reading the data being done via references there is nothing in that
> article to suggest that.
>
> > http://msdn.microsoft.com/en-us/library/ff650849.aspx
> > Here is a more technical discussion about the singleton class is
> implemented in .NET. Application variables are provided by an instance of a
> singleton class (the HttpApplication class).
>
> Looks no different to the way you'd implement a singleton in PHP (as
> expected - as a concept it doesn't generally change between languages).
> Just because the HttpApplication class is a singleton doesn't mean that
> when you request data from it you get it by reference.
>

Could we just for the sake of argument, just accept that it does actually
pass by reference between threads, but not between processes ? It does - is
that really so hard to believe ?


>
> >
> http://stackoverflow.com/questions/1132373/do-asp-net-application-variables-pass-by-reference-or-value
> > Stack overflow question from someone actually wanting to get a *copy* of
> an application variable rather than a reference.
>
> According to that page scalar values are returned by value, objects are
> returned as a copy of the reference. Based on that, it would appear that
> you are correct as far as objects are concerned. However, the advice given
> on several pages I've found, including at least one that you've specified,
> is to use application variables lightly and sparingly. It's not something
> that should be used for petabytes of data, mainly because it's all STORED
> IN MEMORY.
>

see previous comments about petabytes. 50Mb or even 5GB is fine to store in
Applications variables if you have the RAM.


>
> > So, if you read enough of this stuff, you'll find out that a .NET
> website (an IIS application in MS parlance) runs in a multi-threaded single
> process. Application variables (and singleton classes) are shared by
> reference between all threads. It is possible to run an IIS application
> over multiple processes (to take advantage of multiple processors / server
> farms for example) but then the Application variables are not shared at
> all. (This is then pretty comparable to the situation with node.js except
> that node is not multi-threaded)
>
> Single process. Yes. Precisely. PHP *DOES NOT WORK LIKE THIS* and probably
> never will, therefore it's not comparable. And why do you insist on
> comparing anything with Node.js? Node is specifically single-process and,
> as far as the JS developer is concerned, single-threaded. Node can't share
> data across processes in the same way PHP can't. They're also completely
> different architectures... Node implements the web server within the Node
> process, PHP does not. It's not logical to say that an apple should be like
> an orange.
>

I'm trying to point out an area where PHP is currently at a significant
performance disadvantage yet has the possibility to turn this to
significant advantage by "simply" enabling apc_fetch to returning a
reference rather than a value.

Both .NET and node.js both currently have a very significant performance
advantage due to the ability to share data between requests by reference,
rather than by copy as per php.

If apc_fetch were to implement this behaviour PHP would gain a significant
performance advantage because it could share objects between processes
compared .NET's ability to only share between threads (and node's single
thread).


>
> I don't understand why we're still talking about this. The architecture of
> PHP does not make sharing data by reference possible, regardless of whether
> that's how ASP.net works.


You may choose not to want it. But that doesn't mean it's impossible.


> It's irrelevant and frankly I couldn't care less (which I think I've
> mentioned before). I used to use ASP and ASP.net, so I am familiar with
> application variables, but I've never missed them since moving on to other
> technologies. This could be related to the fact that when I moved away from
> ASP I also moved on to far higher levels of traffic than I had ever dealt
> with before.
>



>
> You said that memcached was slow compared to the .net application
> variables; of this I have no doubt. But again, that's irrelevant. The .net
> application variables cannot scale beyond a single process; memcached can
> comfortably scale to many thousands of servers and beyond.
>

Totally agree. One of the links I posted even suggested memcache at this
point. However, you still might store data locally in Application variables
(or more likely the .NET cache) to saving hitting the relatively slow
memcached.


>
> I use a combination of generated PHP files (for things that don't change
> one the app is running), memcached (for things that do), and many other
> technologies to build web applications that serve many millions of users
> every day, and I have no complaints. Per-process (or even per-server)
> application variables never cross my mind - they just don't provide any
> significant benefit.
>
> If you want PHP to work the way .net works, modify PHP yourself or pay
> someone to do it for you, because I practically guarantee that you'll find
> next to no support for moving away from the shared-nothing architecture of
> the PHP core.
>

This may happen


>
> Alternatively... stick to ASP.net.


I'm sorry that I appear to be pissing you off.

It's cool if you want to maintain a "shared nothing" architecture (whilst
ironically using apc_fetch, shm and memcached)



>
> I'm done.
>
> -Stuart
>
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/
>

--- End Message ---
--- Begin Message ---
On Mon, Apr 2, 2012 at 4:34 AM, Maciek Sokolewicz
<maciek.sokolew...@gmail.com> wrote:
> Usually if you think you need to use eval: think again. In this case, it
> again holds true.
>
> Instead of doing what you do, you can also reference the variable as:
> echo ${'image_'.$i};
> or
> echo $GLOBALS['image_'.$i];
>
> Both are preferable by far over using eval, with all its potential security
> concerns.

Oh, man, this is a great list. I didn't even *think* about doing it that way.

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

 

Hey guys, I figured out my critical error. I have a table that has a limit
of 30 rows.

How can I add more rows to a table so that we can upload more images?

Below is what I need to change.

 

Thanks, karl

 

 


Indexes:
<http://dev.mysql.com/doc/refman/5.0/en/optimizing-database-structure.html>
Description: Documentation


Keyname

Type

Cardinality

Action

Field


PRIMARY

PRIMARY

30 

 
<http://www.axiton.com:444/phpMyAdmin/tbl_indexes.php?db=axiton&table=produc
t&token=879a7b6914f690825a521dd29c2f0736&goto=tbl_structure.php&back=tbl_str
ucture.php&index=PRIMARY&phpMyAdmin=0b5ebd941a4bbe87db1e38f60fd10dadec30e8e7
> Description: Edit

 
<http://www.axiton.com:444/phpMyAdmin/sql.php?db=axiton&table=product&token=
879a7b6914f690825a521dd29c2f0736&goto=tbl_structure.php&back=tbl_structure.p
hp&sql_query=ALTER+TABLE+%60product%60+DROP+PRIMARY+KEY&zero_rows=The+primar
y+key+has+been+dropped&phpMyAdmin=0b5ebd941a4bbe87db1e38f60fd10dadec30e8e7>
Description: Drop

product_id

                                                

 

 

 

 <mailto:karlja...@tampabay.rr.com> Karl James

"Need Web Design" Check Out

My Site:  <http://kjwebsitedesign.com/> http://kjwebsitedesign.com

"Flexible in Cost, Time, and Service."

 


--- End Message ---
--- Begin Message ---
On Mon, Apr 2, 2012 at 5:46 PM, Karl James <karlja...@tampabay.rr.com>wrote:

> Hello,****
>
> ** **
>
> Hey guys, I figured out my critical error. I have a table that has a limit
> of 30 rows.****
>
> How can I add more rows to a table so that we can upload more images?****
>
> Below is what I need to change.****
>
> ** **
>
> Thanks, karl****
>
> ** **
>
> ** **
>
> *Indexes: **[image: Description: 
> Documentation]*<http://dev.mysql.com/doc/refman/5.0/en/optimizing-database-structure.html>
> **
>
> *Keyname*
>
> *Type*
>
> *Cardinality*
>
> *Action*
>
> *Field*
>
> *PRIMARY*
>
> PRIMARY****
>
> 30 ****
>
> [image: Description: 
> Edit]<http://www.axiton.com:444/phpMyAdmin/tbl_indexes.php?db=axiton&table=product&token=879a7b6914f690825a521dd29c2f0736&goto=tbl_structure.php&back=tbl_structure.php&index=PRIMARY&phpMyAdmin=0b5ebd941a4bbe87db1e38f60fd10dadec30e8e7>
> ****
>
> [image: Description: 
> Drop]<http://www.axiton.com:444/phpMyAdmin/sql.php?db=axiton&table=product&token=879a7b6914f690825a521dd29c2f0736&goto=tbl_structure.php&back=tbl_structure.php&sql_query=ALTER+TABLE+%60product%60+DROP+PRIMARY+KEY&zero_rows=The+primary+key+has+been+dropped&phpMyAdmin=0b5ebd941a4bbe87db1e38f60fd10dadec30e8e7>
> ****
>
> product_id****
>
> ** **
>
> ** **
>
> ** **
>
> Karl James <karlja...@tampabay.rr.com>****
>
> "Need Web Design" Check Out****
>
> My Site: http://kjwebsitedesign.com****
>
> "*Flexible in Cost, Time, and Service."*****
>
> ** **
>

1) Wrong list for the question
2) Since you've chosen this line of profession, pick up a "SQL
Fundamentals" or "Fundamentals of SQL" book

HTH,
Tommy

--- End Message ---

Reply via email to