Re: [PHP] whats wrong

2012-03-31 Thread Tommy Pham
On Fri, Mar 30, 2012 at 11:45 PM, saeed ahmed  wrote:
> i have made a php script with a tutorial helpi dont know where is a
> error.please have a look
>

Your code below assumes that everything is perfect in your world.  IE:
 no network connectivity issue, all firewall related are properly
configured, the user account actually exists and have the right
permissions, the database exists and so are the table(s), etc  I
suggest you revisit the official PHP manual and read about each
function you're using.

>
>  //connect and select a database
> mysql_connect("localhost","root"," " );

for starters,

http://php.net/function.mysql-connect

Noticed the result returned.  You didn't bother to check whether if
it's successful or not.  If not why not?  Since the DB is on the same
box, is the firewall, if any, configured properly?  If there's no
firewall or if it's configured properly, is the account valid and have
the right permissions?  Is the MySQL server running on the default
port 3306?

If you don't know how to configure each of the above mentioned, allow
me to introduce you a new friend, Google ;)  Both of those topics are
beyond the scope of this list.

HTH,
Tommy

> mysql_select_db("addressbook");
> //Run a query
> $result=mysql_query("select("SELECT*FROM COLLEAGUE");
> ?>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
> 
> Address Book
>  
> 
> Address Book
>  summary="table holda colleague contacts information">
> 
>  ID
> First Name
> Last Name
> Telephone
> Email Address
> 
>  //LOOP through all table rows
> while ($row=mysql_fetch_array($result)) {
> echo"";
> echo"".$row['id'] . ";
> echo "" . $row['firstName'] . "";
> echo "" . $row['lastName'] . "";
> echo "" . $row['telephone'] . "";
> echo "" . Srow['email'] . " echo"";
> }
> //free result memory and close database connection
> mysql_free_result($result);
> mysql_close();
> ?>
> 
> 
> 
> thanks

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] some good deals on good books

2012-03-31 Thread Tommy Pham
On Sat, Mar 31, 2012 at 12:02 AM, tamouse mailing lists
 wrote:
>
> ( I apologize if this offends anyone's sensibilities. I am not in the
> employ of O'Reilly, nor is this going to make me any scratch. I just
> think this is a good chance to pick up some pretty useful books. )
>

Makes a lot of sense to me for someone kind enough to share a great
offer to fellow coders/hackers :)

Thanks.  I'll pass this along to the folks newly interested in PHP.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] securing a script that exec()s

2012-03-31 Thread tamouse mailing lists
On Sat, Mar 31, 2012 at 1:37 AM, rene7705  wrote:
> escapeshellcmd() seems simplest.

It might be if all you care about are shell meta characters, and
admittedly it will save you from someone entering "& rm -rf / &" in
your input field. But dealing with generic user input, even escaped,
can still be problematic. Say you want to let the user set the size of
the output file, and the user enters a bunch of letters instead of a
geometry. Do you really want to have to deal with all the possible
ramifications of such GIGO stuff? Better to vet the data, untaint it,
and deal with it that way. When you've gone to all that, you're almost
all the way to where you need to be to use the library functions.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] whats wrong

2012-03-31 Thread Duken Marga
Please check this line:
> $result=mysql_query("select("SELECT*FROM COLLEAGUE");

I think it should be:
 > $result=mysql_query("SELECT * FROM COLLEAGUE");

On Sat, Mar 31, 2012 at 1:45 PM, saeed ahmed wrote:

> i have made a php script with a tutorial helpi dont know where is a
> error.please have a look
>
>
>  //connect and select a database
> mysql_connect("localhost","root"," " );
> mysql_select_db("addressbook");
> //Run a query
> $result=mysql_query("select("SELECT*FROM COLLEAGUE");
> ?>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
> 
> Address Book
>  
> 
> Address Book
>  summary="table holda colleague contacts information">
> 
>  ID
> First Name
> Last Name
> Telephone
> Email Address
> 
>  //LOOP through all table rows
> while ($row=mysql_fetch_array($result)) {
> echo"";
> echo"".$row['id'] . ";
> echo "" . $row['firstName'] . "";
> echo "" . $row['lastName'] . "";
> echo "" . $row['telephone'] . "";
> echo "" . Srow['email'] . " echo"";
> }
> //free result memory and close database connection
> mysql_free_result($result);
> mysql_close();
> ?>
> 
> 
> 
> thanks
>



-- 
Duken Marga


[PHP] Att: saeed ahmed

2012-03-31 Thread Karl-Arne Gjersøyen
Try this:

mysql> CREATE DATABASE addressbook;
Query OK, 1 row affected (0.00 sec)

mysql> USE addressbook;
Database changed

mysql> CREATE TABLE userData(id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
 firstName VARCHAR(50) NOT NULL,
 lastName VARCHAR(50) NOT NULL,
 telephone INT(12) NOT NULL,
 email VARCHAR(100) NOT NULL);
Query OK, 0 rows affected (0.11 sec)

Now when you have the databse created and a table to store data, you
need to write a PHP page that do the trick.
Here is a simpe sample. Read all comments and look at the source code...

http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
http://www.w3.org/1999/xhtml"; xml:lang="en">


Addressbook







   Contact info:
   
   First Name:
   
   
   
   Last Name:
   
   
   
   Telephone:
   
   
   
   Email Address:
   
   
   
   
   




The Contact information is registred";
}
?>

View Contact Info

First Name: $firstName";
echo "Last Name: $lastName";
echo "Telephone: $telephone";
echo "Email: $email";
echo "";
}
}

?>



Hope this can be in help for you.

Karl
-- 
Hjemmeside: http://www.karl-arne.name/



Den 08:45 31. mars 2012 skrev saeed ahmed  følgende:
> i have made a php script with a tutorial helpi dont know where is a
> error.please have a look
>
>
>  //connect and select a database
> mysql_connect("localhost","root"," " );
> mysql_select_db("addressbook");
> //Run a query
> $result=mysql_query("select("SELECT*FROM COLLEAGUE");
> ?>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> http://www.w3.org/1999/xhtml";>
> 
> Address Book
>  
> 
> Address Book
>  summary="table holda colleague contacts information">
> 
>  ID
> First Name
> Last Name
> Telephone
> Email Address
> 
>  //LOOP through all table rows
> while ($row=mysql_fetch_array($result)) {
> echo"";
> echo"".$row['id'] . ";
> echo "" . $row['firstName'] . "";
> echo "" . $row['lastName'] . "";
> echo "" . $row['telephone'] . "";
> echo "" . Srow['email'] . " echo"";
> }
> //free result memory and close database connection
> mysql_free_result($result);
> mysql_close();
> ?>
> 
> 
> 
> thanks

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] whats wrong

2012-03-31 Thread tamouse mailing lists
On Sat, Mar 31, 2012 at 1:45 AM, saeed ahmed  wrote:
> i have made a php script with a tutorial helpi dont know where is a
> error.please have a look

Before you actually run code in a browser, check your syntax with php
-l (for "lint", the old command to check C syntax on unixy systems) on
a command line. This will improve your life immeasurably since you
won't have to chase down where the server logs errors just to see if
your code was syntactically correct.

miishka:Sites tamara$ php -l test.saeed.php
PHP Parse error:  syntax error, unexpected T_STRING in test.saeed.php on line 6
Errors parsing test.saeed.php
miishka:Sites tamara$

Which points out the syntax error on line 6 where you have:

  $result=mysql_query("select("SELECT*FROM COLLEAGUE");

Which as an improperly formed select sql, and an unclosed string (thus
sucking up part of your php code and html document. To fix this, it
should be:

  $result=mysql_query($db, "SELECT * FROM COLLEAGUE");

i.e., the sql statement is in a single string. Also, spacing around
the column list "*" may or may not be necessary, but it's a lot easier
to read if it's there. Also, you need to tell the query procedure what
data base you're using the $db variable (see below for this).

Ok, that fixed, run php -l on the file again, and we get:

   PHP Parse error:  syntax error, unexpected '>' in test.saeed.php on line 31
   Errors parsing test.saeed.php

Looking at line 31:

   echo "" . $row['firstName'] . "";

it looks fine, you might be wondering why it's complaining about that
line. The key is to look up from there for possible syntax problems,
and on line 30, there is a problem in that you didn't close the last
string:

   echo"".$row['id'] . ";

should be:

   echo"".$row['id'] . "";


Ok, fix that, run php -l again:

   PHP Parse error:  syntax error, unexpected '[', expecting ',' or
';' in test.saeed.php on line 34
   Errors parsing test.saeed.php

So, look at line 34 now:

   echo "" . Srow['email'] . "" . $row['email'] . "" . $row['email'] . "";

Run php -l again, and this time, voila:

   No syntax errors detected in test.saeed.php

That solves your syntax errors. Now you can test it from a server.

Before you do that though, a few other points:

When developing code, it's a really good idea to turn on run time
error checking so you can see things in the browser when a problem
crops up:

  " since you're using XHTML.

Line 39 needs to have the data base resource as well that was set
above in the connect:

   mysql_close($db);

You owe me one internet bheer for debugging your script. :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Could apc_fetch return a pointer to data in shared memory ?

2012-03-31 Thread Stuart Dallas
On 31 Mar 2012, at 02:33, Simon wrote:

> Or: Why doesn't PHP have Applications variables like ASP.NET  (and node.js)
> ?
> 
> Hi,
> 
> I'm working on optimising a php application (Drupal).
> 
> The best optimisation I've found so far is to use APC to store various bits
> of Drupal data in RAM.
> 
> The problem with this is that with Drupal requiring say 50Mb of data* per
> request is that lots of cpu cycles are wasted de-serialising data out of
> apc_fetch. Also 50Mb of data per http process !! is wasted by each one
> re-creating it's own copy of the shared data.

50MB? WTF is it storing?? I've never used Drupal, but based purely on that it 
sounds like an extremely inefficient piece of software that's best avoided!

> If it were possible for apc_fetch (or similar function) to return a pointer
> to the data rather than a copy of the data this would enable incredible
> reduction in cpu and memory usage.

Vanilla PHP adheres to a principle known as "shared nothing architecture" in 
which, shockingly, nothing is shared between processes or requests. This is 
primarily for scalability reasons; if you stick to the shared nothing approach 
your application should be easily scalable.

> This is essentially how ASP.NET Application variables and node.js work.

Not a valid comparison. Node.js applications can only share variables within a 
single process, and they can do so because it's single-threaded. Once you scale 
your app beyond a single process you'd need to add a custom layer on to share 
data between them.

I'm not sure about the architecture behind IIS and ASP.net but I imagine there 
are similar paradigms at work.

> I'm surprised PHP doesn't already have Application variables, given that
> they are so similar to Session Variables and that it's been around for a
> long time in ASP / ASP.NET.

Just because x does it, doesn't mean y should. I've used lots of languages over 
the years, including classic ASP, ASP.net, Perl, Python, Ruby, PHP (obv), and 
more, and I'm yet to see a compelling reason to want application variables. Let 
go of the possibility of application variables and your thinking will shift to 
other ways of solving the problem.

> I just wondered if there was a reason for not having this functionality or
> if it's on a road map somewhere or I've missed something :) ?


As far as I am aware, ASP and ASP.net are the only web technologies to support 
application variables out of the box. You think that's simply because the 
others just haven't gotten around to it yet?

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] whats wrong

2012-03-31 Thread Maciek Sokolewicz

On 31-03-2012 10:29, tamouse mailing lists wrote:

On Sat, Mar 31, 2012 at 1:45 AM, saeed ahmed  wrote:

i have made a php script with a tutorial helpi dont know where is a
error.please have a look


Before you actually run code in a browser, check your syntax with php
-l (for "lint", the old command to check C syntax on unixy systems) on
a command line. This will improve your life immeasurably since you
won't have to chase down where the server logs errors just to see if
your code was syntactically correct.

miishka:Sites tamara$ php -l test.saeed.php
PHP Parse error:  syntax error, unexpected T_STRING in test.saeed.php on line 6
Errors parsing test.saeed.php
miishka:Sites tamara$

Which points out the syntax error on line 6 where you have:

   $result=mysql_query("select("SELECT*FROM COLLEAGUE");

Which as an improperly formed select sql, and an unclosed string (thus
sucking up part of your php code and html document. To fix this, it
should be:

   $result=mysql_query($db, "SELECT * FROM COLLEAGUE");


Wrong, it should be the other way around. First the query, and then an 
OPTIONAL link-identifier (which I assume $db to be in this case).


i.e., the sql statement is in a single string. Also, spacing around
the column list "*" may or may not be necessary, but it's a lot easier
to read if it's there. Also, you need to tell the query procedure what
data base you're using the $db variable (see below for this).

Ok, that fixed, run php -l on the file again, and we get:

PHP Parse error:  syntax error, unexpected '>' in test.saeed.php on line 31
Errors parsing test.saeed.php

Looking at line 31:

echo "" . $row['firstName'] ."";

it looks fine, you might be wondering why it's complaining about that
line. The key is to look up from there for possible syntax problems,
and on line 30, there is a problem in that you didn't close the last
string:

echo"".$row['id'] .";

should be:

echo"".$row['id'] ."";


Ok, fix that, run php -l again:

PHP Parse error:  syntax error, unexpected '[', expecting ',' or
';' in test.saeed.php on line 34
Errors parsing test.saeed.php

So, look at line 34 now:

echo "" . Srow['email'] ."" . $row['email'] ."" . $row['email'] ."";

Run php -l again, and this time, voila:

No syntax errors detected in test.saeed.php

That solves your syntax errors. Now you can test it from a server.

Before you do that though, a few other points:

When developing code, it's a really good idea to turn on run time
error checking so you can see things in the browser when a problem
crops up:

   

Again, query first, linkidentifier after that. This way you'll always 
get an error.



if (FALSE === $result) die ("Query failed. \$sql=$sql. Error: " .
mysql_error($db) . PHP_EOL);

A little further on, there is a problem in the html meta statement:
there is no closer on that line:

" since you're using XHTML.

Line 39 needs to have the data base resource as well that was set
above in the connect:

mysql_close($db);

You owe me one internet bheer for debugging your script. :)


You made mistakes during debugging :s


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Watch out for automatic type casting

2012-03-31 Thread Maciek Sokolewicz

On 30-03-2012 09:47, Arno Kuhl wrote:

-Original Message-
From: Simon Schick [mailto:simonsimc...@googlemail.com]
Sent: 29 March 2012 07:19 PM
To: a...@dotcontent.net
Cc: php-general@lists.php.net
Subject: Re: [PHP] Watch out for automatic type casting

Hi, Arno

FYI: I found a page in the php-manual that's exactly for that:
http://www.php.net/manual/en/language.operators.precedence.php

p.s. some of them were also new to me  Thanks for getting me to read it.

Bye
Simon


Thanks Simon and others, thought it was typecasting, but precedence makes more 
sense.

I remember seeing that table when I first started using php, which is why I always use 
AND and OR rather than&&  and || because it's lower precedence than the 
assignment and the ternary operators, but I couldn't remember where I'd seen it. So 
thanks for linking to it.

Cheers
Arno
--

BTW interesting to note on that precedence page that "!" has a higher precedence than 
"=" (which you'd expect it to be) but you can still do
if (!$a = foo())

I use that form often (as I'm sure many others do) and just took it for granted 
that it works even though the order of precedence says it shouldn't.

It could be expanded to
if ($a = foo() != TRUE)
But that wouldn't get the expected result due to order of precedence, though at 
first glance you could reasonably expect it to work because of
if (!$a = foo())
being valid.

I think that's why it's so easy to be caught out (at least for me) by the 
similar form of
if ( $pos = strpos($sText, "test") !== FALSE)

Cheers
Arno

I would still suggest to explicitly supply the precedence you expect. 
Ie: if(($foo = $var) == true) { }

or if($a + (15*$b) ) { }

I know you can write it with fewer parentheses, but this at least makes 
it 100% clear you at all times WHAT is supposed to happen and you're 
100% sure that PHP will understand what you WANT it to do aswell instead 
of having to guess, and fail at it because you don't know how guessing 
is implemented in the Zend Engine.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Websocket using php

2012-03-31 Thread Leandro Dardini
Hello,
I have the need to use websockets for the server part of an application I
am developing and I found with a big surprise no websocket class or
procedure is available on the net. Have I missed looking in some place?

Being really interested in using this protocol with PHP, I start from the
closest working thing: http://code.google.com/p/phpwebsocket/ and start
adapting it to the lastest RFC describing the protocol
http://tools.ietf.org/html/rfc6455, but it is really heavy to code and I
feel like "reinventing the wheel".

Is there anyone out there who has already written a websocket server in PHP
and like to share the code?

Leandro


Re: [PHP] Thinking out loud - a continuation...

2012-03-31 Thread Jay Blanchard

[snip]
On 3/30/2012 1:14 PM, Robert Cummings wrote:

On 12-03-27 11:11 AM, Jay Blanchard wrote:

[snip]On 3/27/2012 12:21 AM, Robert Cummings wrote:

>> [-- SNIP --]

Essentially, entries at the root and entries for the children are just
auto indexed array items but the actual entries in those arrays retain
the associative index structure for retrieval of the specific
information. let me know and I can probably whip you up something.


Robert that looks correct. Here is an example of the JSON that the guy
provided for me -

   var json = {
  id: "node02",
  name: "0.2",
  data: {},
  children: [{
  id: "node13",
  name: "1.3",
  data: {},
  children: [{
  id: "node24",
  name: "2.4",
  data: {},
  children: [{
  id: "node35",
  name: "3.5",
  data: {},
  children: [{
  id: "node46",
  name: "4.6",
  data: {},
  children: []
  }]
  }, {
  id: "node37",
  name: "3.7",
  data: {},
  children: [{
  id: "node48",
  name: "4.8",
  data: {},
  children: []
  }, {
  id: "node49",
  name: "4.9",
  data: {},
  children: []
  }, {
  id: "node410",
  name: "4.10",
  data: {},
  children: []
  }, {
  id: "node411",
  name: "4.11",
  data: {},
  children: []
  }]
  },
Of course he properly closes up the JSON. I inserted id's (just an
auto-incrementing number) and the data portion where needed. The name:
is the part that has been the result of what you did before.


Here's the code... I did a bit of shuffling and actually tested 
against a test db table:




And here's the code:

getConnectionRef();

$query =
"SELECT DISTINCT "
   ."   * "
   ."FROM "
   ."   tiers "
   ."WHERE "
   ."   company = {$company} ";

$root = array();
if( $db->query( $query ) )
{
while( ($row = $db->fetchRow()) )
{
$focus = &$root;
for( $i = 1; $i <= 14; $i++ )
{
$name = trim( $row['tier'.$i] );
if( $name === '' )
{
break;
}

if( !isset( $focus[$name] ) )
{
$focus[$name] = array
(
'name' => $name,
'children' => array(),
);
}

$focus = &$focus[$name]['children'];
}
}
}

$wrapper = array
(
'children' => &$root
);

postProcessTiers( $wrapper );

return $root;
}

function postProcessTiers( &$root )
{
$root['children'] = array_values( $root['children'] );

foreach( array_keys( $root['children'] ) as $index )
{
postProcessTiers( $root['children'][$index] );
}
}

function getTiersJson( $company )
{
$tiers = getTiers( $company );
$json = JSON_encode( $tiers );
}

$tiersJson = getTiersJson( 1 );

?>

This will output JSON with the following structure:



PHP is smart enough to detect an array that only has consecutive 
integer keys and create the appropriate JavaScript array object. So we 
don't have to do any special processing of the JSON after we've post 
processed the tier structure itself.

[/snip]

Thanks Robert - I'll give this a go later today.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Node.PHP

2012-03-31 Thread Daniel Brown
On Fri, Mar 30, 2012 at 21:33, Michael Save
 wrote:
> Because "normal" PHP is not asynchronous.
>
> Also, I kind of doubt you can outperform node.js with standard PHP.

Your doubts are indeed well-grounded.  Using node.js (indeed,
V8-based apps in general) are compiled as native machine code, which
don't require the added overhead of a parser, such as PHP.  With that
said, compiling PHP (such as with HopHop) would give at least
comparable performance results.

Still, all in all, I would never discourage someone doing a
'node.php' application.  While its performance may not be quite as
good speed-wise, that doesn't mean it can't become more robust, more
generally-applicable, or even just find niche uses.  I've written
numerous socket servers in PHP for a variety of clients and uses,
where they made sense (speed of deployment, ease of code-management by
a number of developers who don't know C, et cetera).  I can easily see
where this could add value.

-- 

Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] some good deals on good books

2012-03-31 Thread Daniel Brown
On Sat, Mar 31, 2012 at 03:02, tamouse mailing lists
 wrote:
> I know there are quite a few people here who are just beginning to
> learn how to write programs as they also learn about PHP. O'Reilly has
> a deal on some pretty important books available electronically, save
> 50%. If this appeals to you, head to <
> http://shop.oreilly.com/category/deals/essential-code.do > and check
> them out.
>
> ( I apologize if this offends anyone's sensibilities. I am not in the
> employ of O'Reilly, nor is this going to make me any scratch. I just
> think this is a good chance to pick up some pretty useful books. )

There was no affiliate code, so it doesn't appear as though there
was any ulterior motive.  As such, if anyone is offended, perhaps they
don't quite possess "sensibilities."  ;-P

The link you provided will also benefit a lot who read the list
via numerous external sources, such as forums that auto-populate with
content from these lists, and the archives, which are slurped by
Google so quickly that, on occasion, I've seen posts show up in Google
before I even get the chance to read the original email.

Great job on a thoughtful post.

-- 

Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Websocket using php

2012-03-31 Thread Matijn Woudt
On Sat, Mar 31, 2012 at 5:14 PM, Leandro Dardini  wrote:
> Hello,
> I have the need to use websockets for the server part of an application I
> am developing and I found with a big surprise no websocket class or
> procedure is available on the net. Have I missed looking in some place?
>
> Being really interested in using this protocol with PHP, I start from the
> closest working thing: http://code.google.com/p/phpwebsocket/ and start
> adapting it to the lastest RFC describing the protocol
> http://tools.ietf.org/html/rfc6455, but it is really heavy to code and I
> feel like "reinventing the wheel".
>
> Is there anyone out there who has already written a websocket server in PHP
> and like to share the code?
>
> Leandro

Have you tried http://code.google.com/p/phpws/ ?

It seems to work pretty simple..

- Matijn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Could apc_fetch return a pointer to data in shared memory ?

2012-03-31 Thread Stuart Dallas
On 31 Mar 2012, at 13:14, Simon wrote:

> Thanks again Stuart.
> 
> On 31 March 2012 12:50, Stuart Dallas  wrote:
>> On 31 March 2012 11:19, Simon  wrote:
>> Thanks for your answer.
>> 
>> On 31 March 2012 09:50, Stuart Dallas  wrote:
>> On 31 Mar 2012, at 02:33, Simon wrote:
>> 
>> > Or: Why doesn't PHP have Applications variables like ASP.NET  (and node.js)
>> > ?
>> >
>> > Hi,
>> >
>> > I'm working on optimising a php application (Drupal).
>> >
>> > The best optimisation I've found so far is to use APC to store various bits
>> > of Drupal data in RAM.
>> >
>> > The problem with this is that with Drupal requiring say 50Mb of data* per
>> > request is that lots of cpu cycles are wasted de-serialising data out of
>> > apc_fetch. Also 50Mb of data per http process !! is wasted by each one
>> > re-creating it's own copy of the shared data.
>> 
>> 50MB? WTF is it storing?? I've never used Drupal, but based purely on that 
>> it sounds like an extremely inefficient piece of software that's best 
>> avoided!
>> 
>> All sorts of stuff (taxonomies, lists of data, menu structures, 
>> configuration settings, content etc). Drupal is a sophisticated application. 
>> Besides, 50Mb of data seems like relatively tiny "application state" to want 
>> to access in fastest possible way. It's not hard to imagine wanting to use 
>> *much* more than this in future
>>  
>> 
>> > If it were possible for apc_fetch (or similar function) to return a pointer
>> > to the data rather than a copy of the data this would enable incredible
>> > reduction in cpu and memory usage.
>> 
>> Vanilla PHP adheres to a principle known as "shared nothing architecture" in 
>> which, shockingly, nothing is shared between processes or requests. This is 
>> primarily for scalability reasons; if you stick to the shared nothing 
>> approach your application should be easily scalable.
>> 
>> Yes, I know. I think the effect of this is that php will scale better (on 
>> average) in situations where requests don't need to share much data such as 
>> "shared hosting". In an enterprise enviroment where the whole server might 
>> be dedicated to single application, "shared nothing" seems to be a synonym 
>> for "re-load everything" ?
>> 
>> Yes, on one level that is what it means, but alternatively it could mean 
>> being a lot more conservative about what you load for each request.
> 
> Um, I want to be *less* conservative. Possibly *much* less. (like Gigabyes or 
> even eventually Petabytes of shared data !)

We appear to have drifted off the point. There's a big difference between data 
that an application needs to access and "application variables".

What you're describing is a database. If you want something more performant 
there are ways to optimise access to that amount of data, but if not I've 
completely lost what the problem is that you're trying to solve.

>> > This is essentially how ASP.NET Application variables and node.js work.
>> 
>> Not a valid comparison. Node.js applications can only share variables within 
>> a single process, and they can do so because it's single-threaded. Once you 
>> scale your app beyond a single process you'd need to add a custom layer on 
>> to share data between them.
>> 
>> I'm not sure about the architecture behind IIS and ASP.net but I imagine 
>> there are similar paradigms at work.
>> 
>> I totally agree although,  I *think* IIS uses multiple threads running in a 
>> single process (or "Application Pool").
>> I realise that ASP.NET / node.js have their own architectural issues but I'm 
>> confident that for enterprise applications
>> (ie Drupal) the option for "shared something" is capable of many orders of 
>> magnitude higher performance and scalability than "shared nothing".
>> 
>> And that's why there are so many options around that enable such 
>> functionality. The need for something doesn't in any way imply that it 
>> should be part of the core system. Consider the impact such a requirement 
>> would have on the environment in which you run PHP. By delegating that 
>> "feature" to third-party modules, the PHP core doesn't need to concern 
>> itself with the details of how to share data between processes on every 
>> target platform.
> 
> Agreed. If you were able to point me in the direction of such a 3rd party 
> module I'd be a very happy man.

APC and memcached are two of the most common examples, other than the vast 
array of DBMSes out there.
 
>> > I'm surprised PHP doesn't already have Application variables, given that
>> > they are so similar to Session Variables and that it's been around for a
>> > long time in ASP / ASP.NET.
>> 
>> Just because x does it, doesn't mean y should. I've used lots of languages 
>> over the years, including classic ASP, ASP.net, Perl, Python, Ruby, PHP 
>> (obv), and more, and I'm yet to see a compelling reason to want application 
>> variables. 
>> 
>> The reason that I'm suggesting this is because taking the example of Drupal, 
>> the ability to share information