[PHP] Fwd: Help - removal of trailing zeros from double integer field

2001-01-20 Thread ravi

Dear friends,

I am accessing MySQL database using apache and php.
I have to display a double integer field without trailing zeros.
The number of digits after the decimal point varies.

I have tried searching the archive and did not get any previous questions.

Kindly help me in this regard.

Thanking you.
Sincerely,
Raveendra Reddy B
National Law School
Bangalore
India
E-mail: [EMAIL PROTECTED]

- End forwarded message -

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Date difference

2001-03-31 Thread ravi

Dear Friends,

I am accessing a MySQL database through PHP.

I have to calculate the difference between todays date and the date obtained 
from MySQL database.

The Database string is in the form of \"-mm-dd\".

I have to convert the above string into unix timestamp so that i can calcualte 
the difference between the two time stamps.

Please help me in this regard.

Thanking you,

B. Raveendra Reddy
National Law School of India University

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Including "Due by" in an email sent from PHP program

2009-06-24 Thread Ravi
Hi: does anyone know how to include a "Due by" attribute with a dare in 
an email that is sent from a PHP script. This value is acts as an 
reminder when the email is in Outlook.


TIA

--
Thank you,
RaVi



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



[PHP] is there any application , by using i can produce php exe files in windows ?

2004-06-20 Thread Ravi
HI,

is there any windows application , by using we can produce standalone php
.exe files ?


--- knowledge is power share it ---

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



[PHP] plz help!compiled php but iam still getting old version ???

2004-06-20 Thread Ravi
HI,

existing configuration :
PHP Version 4.3.4 ( default rpm with fedora fc2 install)
Server version: Apache/2.0.49 (default with fedora fc2 install)
Server built:   May  6 2004 07:15:13

NOw i want to install 4.3.3 , so i compiled and install ( with no errors )
if i type " php -v " at shell iam getting correct version *BUT if tried
phpinfo() in browser iam getting still OLD version :( restarted apache but
no use.

please help

- thanks for your time.





--- knowledge is power share it - ravi.us ---

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



[PHP] newbie questions

2007-10-20 Thread Ravi


Guys, I am fairly new to PHP. Here are a few questions, if anybody can 
answer it will help me get started. Thanks


I am trying to build a website and I would like to do the following in 
my scripts


1. I want to return response to the browser and AFTERWARDS make a log 
entry in to a database. I need this so user can experience a fast response.


2. If the database update fails, I want to ignore it (since it is just 
log entry). Something like try-catch construct in Java. This is more 
important if item1 mentioned above is not possible. Essentially whether 
I make a database entry or not, I must return a valid response to user.


3. Is there something like connection pool in php? Do usually people 
open/close database connection for every request (I doubt that, it 
sounds really slow).



Some code samples or pointers to documentation for the above would also 
be very helpful.


Thanks
Ravi

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



[PHP] Re: newbie questions

2007-10-21 Thread Ravi


That was very very helpful. Thanks a ton!

One more question. For every request, I am sending a redirect back to 
the user and the browser takes the user to another url. The problem is 
that the browser is not redirecting until the script finishes. Even if I 
do flush(), the browser waits til script ends. Is there a way to force 
browser to redirect and not wait for the script to end?


In Java I can think of many ways, one is to use threads, hand of data to 
another thread and return the response. Another solution would be to 
store data in memory (static variable) and update only after every 100 
requests.


Is any of this possible in PHP?


M. Sokolewicz wrote:

Ravi wrote:


Guys, I am fairly new to PHP. Here are a few questions, if anybody can 
answer it will help me get started. Thanks


I am trying to build a website and I would like to do the following in 
my scripts


1. I want to return response to the browser and AFTERWARDS make a log 
entry in to a database. I need this so user can experience a fast 
response.
There is no "before and after". Everything you do happens during (part 
of) the response. But you can just output your data, whatever it may be, 
flush() it and then log it via the same script. Your user won't notice a 
thing (Hell, even without the flush your user won't notice it probably).


2. If the database update fails, I want to ignore it (since it is just 
log entry). Something like try-catch construct in Java. This is more 
important if item1 mentioned above is not possible. Essentially 
whether I make a database entry or not, I must return a valid response 
to user.
So ignore it :) If you don't check for errors, you won't see them... 
Makes debugging very annoying, but you won't see em nevertheless. If 
your output is not based on anything from your database-update, then 
there apparently is no need to worry about it.


3. Is there something like connection pool in php? Do usually people 
open/close database connection for every request (I doubt that, it 
sounds really slow).
There is something like that, the persistent connections (ie. via 
mysql_pconnect), but generally people DO open/close connections via the 
same script each and every time the script is executed (this might sound 
very slow, but it's actually not too bad). Using persistent connections 
is not always the best option (and usually doesn't even make much 
sense); there's a good bit of documentation about it in the php docs:

http://www.php.net/manual/en/features.persistent-connections.php

Some code samples or pointers to documentation for the above would 
also be very helpful.

code samples of what exactly ?


Thanks
Ravi




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



Re: [PHP] Re: newbie questions

2007-10-21 Thread Ravi


Richard, unfortunately I cannot end the script. I need something like this:

http://www.yahoo.com');
// somehow let the browser move to yahoo.com
// now update the database to store some information about user
exit;
?>


Richard Heyes wrote:

Ravi wrote:


That was very very helpful. Thanks a ton!

One more question. For every request, I am sending a redirect back to 
the user and the browser takes the user to another url. The problem is 
that the browser is not redirecting until the script finishes. Even if 
I do flush(), the browser waits til script ends. Is there a way to 
force browser to redirect and not wait for the script to end?


In Java I can think of many ways, one is to use threads, hand of data 
to another thread and return the response. Another solution would be 
to store data in memory (static variable) and update only after every 
100 requests.


Not having read the rest of the thread, you could call exit just after 
the redirect header is sent, eg:


http://www.yahoo.com');
exit;
?>

Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support



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



[PHP] Re: newbie questions

2007-10-21 Thread Ravi


Maybe you have a point. I will do performance testing and then decide if 
I should try to optimize to that point.


Yes the logging is just one simple insert into the database.

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



Re: [PHP] RE: php-general Digest 17 Oct 2005 10:35:46 -0000 Issue 3742

2005-10-17 Thread Ravi
I just had a small doubt..Is it possible to write JavaScript through PHP???

On 10/17/05, Aftab Alam <[EMAIL PROTECTED]> wrote:
> hi,
> any one can help me
>
> i want to generate Pdf file using php.
> how can i & what tools is required for this.
>
>
>
>
>
>
> Regards,
>   _
>
> Aftab Alam
>
>
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Sent: Monday, October 17, 2005 4:06 PM
> To: php-general@lists.php.net
> Subject: php-general Digest 17 Oct 2005 10:35:46 - Issue 3742
>
>
>
> php-general Digest 17 Oct 2005 10:35:46 - Issue 3742
>
> Topics (messages 224207 through 224218):
>
> Funky array question
> 224207 by: Brian Dunning
> 224209 by: Minuk Choi
> 224210 by: Jordan Miller
> 224211 by: Jordan Miller
> 224212 by: Jordan Miller
>
> Re: editor
> 224208 by: yangshiqi1089
>
> a couple of problems with PHP form
> 224213 by: Bruce Gilbert
> 224218 by: Mark Rees
>
> Re: OPTIMIZING - The fastest way to open and show a file
> 224214 by: Ruben Rubio Rey
> 224215 by: Ruben Rubio Rey
> 224216 by: ac
>
> can't get IIS to run php if the script is not directly under wwwroot
> 224217 by: tony yau
>
> 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:
> php-general@lists.php.net
>
>
> --
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



[PHP] ruby / rails within a php site

2009-03-03 Thread ravi Ruddarraju
I have a regular php site. I also have a ruby / rails application. Now I
want to put the HTML generated by ruby / rails application within a 
section of a php page. This should be similar to like calling a php function
within a  section, which would produce the HTML output of the php
function.
Is such a thing possible between php and ruby / rails? Any help will be
appreciated.

Thanks
ravi


Re: [PHP] PDO Prepared Statements and stripslashes

2010-12-20 Thread Ravi Gehlot
Hello,

The plug-in PDO has nothing to do with the backslashes being inserted into
the database. The backslashes are used to escape characters like in D's...it
would show D's. That's the safe behavior of it. You can change
your programming code to fix that.

Ravi.


On Tue, Dec 21, 2010 at 12:59 AM, Rico Secada  wrote:

> On Tue, 21 Dec 2010 00:32:19 -0500
> Paul M Foster  wrote:
>
> > On Tue, Dec 21, 2010 at 05:31:15AM +0100, Rico Secada wrote:
> >
> > > Hi.
> > >
> > > In an article about SQL Injection by Chris Shiflett he mentions the
> > > following in a comment: "The process of escaping should preserve
> > > data, so it should never be necessary to reverse it. When I'm
> > > auditing an application, things like stripslashes() alert me to
> > > design problems."
> > >
> > > Now, I'm always using PHP PDO with prepared statements and as such
> > > data with quotes gets slashed automatically by PDO when inserted
> > > into the database.
> >
> > Just out of idle curiosity, are you using MySQL? PDO shouldn't be
> > backslashing quotes for PostgreSQL, as the PostgreSQL convention for
> > values containing single quotes is to double the quotes, as: ''.
>
> Currently I'm working with MySQL, but I have just tested PDO with
> PostgreSQL 8.3 and in this case PDO backslashes PostgreSQL as well.
>
> > > When I need to pull out the data something might be slashed and I
> > > need to use stripslashes() or some str_replace() to make sure that
> > > the slashes are removed.
> > >
> > > So what's the mistake here and what's the correct way to do it?
> >
> > I don't see a mistake. If the values come out of the database
> > backslashed, then you need to remove them to work with the data. My
> > only question would be whether you're sure the data is backslashed
> > before PDO ever sees it. In which case, yes, you have a problem.
>
> No, the data is not slashed before PDO sees them.
>
> I didn't see a mistake either, but then what does Chris mean? Stripping
> slashes from output from the DB alerts him to a design problem, and
> I'm just wondering if there another way of doing things I just haven't
> heard of then.
>
> > Paul
> >
> > --
> > Paul M. Foster
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Common session for all subdomains?

2010-12-20 Thread Ravi Gehlot
That's a good question.

There should be a setting on php.ini to allow cross session.

Ravi.


On Mon, Dec 20, 2010 at 7:05 PM, Jonathan Tapicer  wrote:

> Hi!
>
> You should use the function session_set_cookie_params to set the
> session cookie domain to ".oire.org" like this comment explains:
> php.net/manual/en/function.session-set-cookie-params.php#94961
>
> Regards,
> Jonathan
>
> On Mon, Dec 20, 2010 at 7:18 PM, Andre Polykanine  wrote:
> > Hello php-general,
> > I've got a question: I have a site http://oire.org/. Then we started
> > developing some applications at http://apps.oire.org/.
> > How can I manage it in the way so the session valid at
> > http://oire.org/ would be also valid at http://apps.oire.org/?
> > Thanks!
> > --
> > With best regards from Ukraine,
> > Andre
> > Skype: Francophile
> > Twitter: http://twitter.com/m_elensule
> > Facebook: http://facebook.com/menelion
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Problem with Include

2010-12-20 Thread Ravi Gehlot
Why mess with something that is already working? If you are trying to make
it pretty then you are not solving a problem. You are creating one.

Ravi.


On Mon, Dec 20, 2010 at 7:40 AM, Daniel P. Brown
wrote:

> On Mon, Dec 20, 2010 at 02:49, Simcha Younger  wrote:
> >
> > Since it is being included by PHP, and not served by Apache, the
> extension is not important.
>
> Correct, but keep in mind that it will likely be served as plain
> text if accessed directly, if the web server is not properly
> configured (which, by default, it isn't).
>
> --
> 
> Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
> (866-) 725-4321
> http://www.parasane.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] All records not displaying...

2010-12-20 Thread Ravi Gehlot
I would say enabled error_reporting(E_ALL); error_reporting(-1);

Then use die(mysql_error()); with your mysql function to get some debugging
data.

Also use var_dump($query_name) to find out what is spits out.

Debugging is your best friend here. If you don't use die() or
error_reporting() then you will see a blank screen.

Ravi.


On Sun, Dec 19, 2010 at 9:01 PM, Gary  wrote:

>
> "Tamara Temple"  wrote in message
> news:c6993909-dd90-4f52-bf6b-ab888c281...@gmail.com...
> >
> > On Dec 19, 2010, at 9:46 AM, Gary wrote:
> >
> >> I have an issue that the first record in a query is not being
>  displayed.
> >> It
> >> seems that the first row in alphabetical order is not being brought  to
> >> the
> >> screen.
> >>
> >> I have run the query in the DB and it displays the correct result,  so
> it
> >> has
> >> to be in the php.
> >>
> >> I have a MySQL DB that lists beers.  I have a column for 'type' of  beer
> >> (imported, domestic, craft, light). The queries:
> >>
> >> $result = MySQL_query("SELECT * FROM beer WHERE type = 'imported'  AND
> >> stock
> >> = 'YES' ORDER by beername ");
> >>
> >> When I run the query
> >>
> >> if (mysql_num_rows($result) == !'0') {
> >>$row = mysql_fetch_array($result);
> >>
> >>  echo 'Imported Beers';
> >>  echo ' >> id="tableone" summary="">
> >>
> >>  Beer
> >>  Maker
> >>  Type
> >>  Singles
> >>  6-Packs
> >>  Cans
> >>  Bottles
> >>  Draft
> >>  Size
> >>  Description';
> >>
> >>  while ($row = mysql_fetch_array($result)) {
> >>
> >> echo '' . $row['beername'].'';
> >> echo '' . $row['manu'] . '';
> >> echo '' . $row['type'] . '';
> >> echo '' . $row['singles'] . '';
> >> echo '' . $row['six'] . '';
> >> echo '' . $row['can'] . '';
> >> echo '' . $row['bottles'] . '';
> >> echo '' . $row['tap'] . '';
> >> echo '' . $row['size'] . '';
> >> echo '' . $row['descrip'] . '';
> >> '';
> >>}
> >> echo '';
> >>
> >> }
> >>
> >> All but the first row in alphabetical order are displayed properly.
> >>
> >> Can anyone tell me where I am going wrong?
> >> --
> >> Gary
> >>
> >> BTW, I do have a bonus question that is about javascript in this  same
> >> file,
> >> so if anyone want to take a stab at that, I'll be happy to post it.
> >>
> >
> > This code will totally eliminate the first row of data.
> >
> >> if (mysql_num_rows($result) == !'0') {
> >>$row = mysql_fetch_array($result);
> >
> > Fetches the first row, but is not output. Because:
> >
> >>  while ($row = mysql_fetch_array($result)) {
> >
> > Fetches the second row before you do any output of the data.
> >
> > Eliminate the first fetch_array and you're code should work fine.
> >
> > BTW, if you put the  attributes 'width="n"' in the preceding 
> > tags, you won't have to output them for each row. You should also put
>  the
> > units those numbers are associated with.
> >
> >
> Tamara
>
> Thank you for your help and thank you for the explaination.  I removed the
> line and it works fine.  I dont remember where or why I had that line in
> there, it is code that I have "recycled" for a while now.
>
> Gary
>
>
>
> __ Information from ESET Smart Security, version of virus signature
> database 5716 (20101219) __
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] array question

2010-12-20 Thread Ravi Gehlot
Jim Lucas has it. You can use the preg_match function to find it. I would
use regexp for that reason. regexp is good for making sure things are typed
the way they need to (mostly used for).

Ravi.


On Sat, Dec 18, 2010 at 5:17 PM, Jim Lucas  wrote:

> On 12/17/2010 12:52 PM, Sorin Buturugeanu wrote:
>
>> Hello all!
>>
>> I have a question regarding arrays and the way I can use a value.
>>
>> Let's say I have this string:
>>
>> $s = 'banana,apple,mellon,grape,nut,orange'
>>
>> I want to explode it, and get the third value. For this I would normally
>> do:
>>
>> $a = explode(',', $s);
>> echo $s[2];
>>
>> That's all fine, but is there a way to get the value directly, without
>> having to write another line in my script. I mean something like this:
>>
>> echo explode(',', $s)[2];
>>
>> or
>>
>> echo {explode(',', $s)}[2];
>>
>> I couldn't find out this answer anywhere, that's why I posted here.
>>
>> Cheers and thanks!
>>
>>
> Sure it CAN be done.  Nobody laugh too loud here... But...
>
> 
> $s = 'banana,apple,mellon,grape,nut,orange';
> echo preg_replace('/([^,]+,){3}([^,]+).*/', '$2', $s);
>
> ?>
> Outputs: grape
>
> The {3} part is equivalent to the array position.  Change that number, and
> you change which word will get displayed.
>
> Jim Lucas
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] PHPInfo disabled due to security

2010-12-20 Thread Ravi Gehlot
Hello there,

If you have a small to medium size web site then go to GoDaddy. Do not
believe all that you see from php_info(). I will give you an example. The
memory_limit it gives on shared hosting does not reflect the one intended
for your shared account. It shows what was set for overall use. But blocking
php_info() isn't right (at least I don't think so).

Ravi.


On Fri, Dec 17, 2010 at 10:25 AM, Daniel Brown  wrote:

> On Thu, Dec 16, 2010 at 23:39, Paul S  wrote:
> >
> > Well, I was hoping for stronger arguments to get that DONE. I would think
> > there be something in the PHP license
> > that would FORBID disabling functionality.
>
> Really?  You would really think that?  Because we wouldn't.
>
> > After all, 'phpinfo' is essential, really, to achieving secure
> > applications, isn't it?
>
> No.  Writing good code is essential.
>
> --
> 
> Network Infrastructure Manager
> Documentation, Webmaster Teams
> http://www.php.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Error Querying Database

2010-12-20 Thread Ravi Gehlot
Trying to connect to the database can involve setting up your database. Make
sure that you have a valid login/password that is recognized by MySQL.
Please keep in mind that MySQL works on permission by hosts. So your host IP
must be matched with the username/password on the database for a successful
authentication. One way to know that you can connect successfully to your
remote database is to actually test it. Download MySQL Workbench from
Mysql.com and then try to connect to remote from the same host that your php
application is sitting at. If it works, thumbs up. If it does not then you
have a permission issue there. Add your username/host appropriately.

If you can connect without a hitch then you are doing something wrong on
your code. Use mysql_connect(), mysql_select_db() and then send an statement
and use the resource to see if it returns TRUE or FALSE. At this point, on
FALSE it means that you have a bad written statement.

There is so much that can go wrong. Debug step by step.

Ravi.


On Thu, Dec 16, 2010 at 9:26 PM, Phred White wrote:

> It seems like there are several questions emerging, but ...
>
> Try echoing your query to the page by putting echo $query in your code
> before you call mysql, then copy it and run it in phpmyadmin. If it runs
> then you know your problem is somewhere else like the connection. This can
> really help you find typos that can cause mysterious results.
>
> If you want to use the same page to process the form (my preference) then
> put a hidden field in your form like:
>
>
>
> and wrap the form processing code like so:
>
> if (isset($_POST['phpaction'])) {
>//process submitted form data
> } else {
>//processing for initial form entry
> }
>
> When the form is initially loaded it will ignore the first part
> There are a 1000 ways to do this, but this is pretty straightforward.
>
> On Dec 15, 2010, at 1:34 PM, Gary wrote:
>
> >
> > "Steve Staples"  wrote in message
> > news:1292440837.5460.8.ca...@webdev01...
> >> On Wed, 2010-12-15 at 13:42 -0500, Gary wrote:
> >>> I cant seem to get this to connect.  This is to my local testing
> server,
> >>> which is on, so we need not worry that I have posted the UN/PW.
> >>>
> >>> This is a duplicate of a script I have used countless times and it
> >>> worked.
> >>> The error message is 'Error querying database.'
> >>>
> >>> Some one point out the error of my ways?
> >>>
> >>> Gary
> >>>
> >>>
> >>> " method="post">
> >>> 
> >>> 
> >>> Name of Beer />
> >>> 
> >>> 
> >>> 
> >>> 
> >>> Maker of Beer
> >>> 
> >>> 
> >>> 
> >>> 
> >>> Type of Beer
> >>> 
> >>>  Imported
> >>>  Domestic
> >>>  Craft
> >>>  Light
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> Sold in
> >>> 
> Singles >>> />
> >>>  Six Packs 
> >>>  Cans
> >>>  Bottles 
> >>>  Draft 
> >>> 
> >>> 
> >>> Size
> >>> 
> >>> 
> >>> Description >>> rows="5">
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>>  >>> $beername = $_POST['beername'];
> >>> $manu = $_POST['manu'];
> >>> $type = $_POST['type'];
> >>> $singles = $_POST['singles'];
> >>> $six = $_POST['six'];
> >>> $can = $_POST['can'];
> >>> $bottles = $_POST['bottles'];
> >>> $tap = $_POST['tap'];
> >>> $size = $_POST['size'];
> >>> $desc = $_POST['desc'];
> >>> $ip= $_SERVER['REMOTE_ADDR'];
> >>>
> >>> $dbc = mysqli_connect('localhost','root','','rr')or die('Error
> connecting
> >>> with MySQL Database');
> >>>
> >>> $query = "INSERT INTO beer (beername, manu, type, singles, six, can,
> >>> bottles, tap, size, desc, ip )"." VALUES ('$beername', '$manu',
> '$type',
> >>> '$singles', '$six', '$can', '$bottles', '$tap', '$size', '$desc',
> >>> &

Re: [PHP] Problem with Include

2010-12-20 Thread Ravi Gehlot
My point is that you tried to take code from one page and put it all
"organized" in another page and the include that page of includes back into
the pages that you want it to feed off from. If stuff works the way that it
does then there a reason for it to have been done that way. That's why
documenting code is so important. 99% doesn't do it (including me).

Ravi.


On Tue, Dec 21, 2010 at 2:35 AM, David Hutto  wrote:

> On Tue, Dec 21, 2010 at 2:29 AM, Ravi Gehlot  wrote:
> > Why mess with something that is already working? If you are trying to
> make
> > it pretty then you are not solving a problem. You are creating one.
>
>
> Define working. I've had programs 'work', but more experienced would
> say it's flawed in some respect. Does it perform the immediate task?
>
> Now define pretty. Is it aesthetically pleasing to you, or to someone
> else with less, or maybe more experience.
>
> By defining the two above, you then define whether it's a problem. To
> you, or to them, or to the original designer?
>
> >
> > Ravi.
> >
> >
> > On Mon, Dec 20, 2010 at 7:40 AM, Daniel P. Brown
> > wrote:
> >
> >> On Mon, Dec 20, 2010 at 02:49, Simcha Younger 
> wrote:
> >> >
> >> > Since it is being included by PHP, and not served by Apache, the
> >> extension is not important.
> >>
> >> Correct, but keep in mind that it will likely be served as plain
> >> text if accessed directly, if the web server is not properly
> >> configured (which, by default, it isn't).
> >>
> >> --
> >> 
> >> Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
> >> (866-) 725-4321
> >> http://www.parasane.net/
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
>
>
>
> --
> They're installing the breathalyzer on my email account next week.
>


Re: [PHP] Problem with Include

2010-12-21 Thread Ravi Gehlot
If something is working and you don't know exactly whats under the hood then
you are wasting your time in trying to re-invent your own wheel and waste
your time and resources to modify something that isn't needed to be touched.
Good programmers make good use of their time as well. We need to keep in
check with new technology, learn new trends and also master our weakness. If
we keep changing this or that or moving that or this then oh well...there
goes 1 day worth of work to figure stuff out.

Just my take on this. If you think different, then no problems.

Regards,
Ravi.


On Tue, Dec 21, 2010 at 10:23 AM, Paul M Foster wrote:

> On Tue, Dec 21, 2010 at 02:35:33AM -0500, David Hutto wrote:
>
> > On Tue, Dec 21, 2010 at 2:29 AM, Ravi Gehlot 
> wrote:
> > > Why mess with something that is already working? If you are trying to
> make
> > > it pretty then you are not solving a problem. You are creating one.
> >
> >
> > Define working. I've had programs 'work', but more experienced would
> > say it's flawed in some respect. Does it perform the immediate task?
> >
> > Now define pretty. Is it aesthetically pleasing to you, or to someone
> > else with less, or maybe more experience.
> >
> > By defining the two above, you then define whether it's a problem. To
> > you, or to them, or to the original designer?
>
> Beware of "more experienced" programmers. I recently talked to an
> ex-boss of mine who had a programmer flake out on him. One of his
> customers threatened to take this flaky code to another company and get
> their opinion about whether it was good code or not. My ex-boss
> explained that, of course, they'd shoot it down. Because that's what
> programmers do-- they complain about other programmers' code. I'd never
> heard that idea expressed aloud. But when I thought about it, I realized
> it was true. Hell, look at the content of this list. ;-}
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] PHPInfo disabled due to security

2010-12-21 Thread Ravi Gehlot
Hello there,

GoDaddy show 20M for their limit size when they only allow a max of 5.6 MB
of upload. So what I mean is don't try what you see from php_info().


Ravi.


On Tue, Dec 21, 2010 at 9:48 AM, Daniel Brown  wrote:

> On Tue, Dec 21, 2010 at 02:40, Ravi Gehlot  wrote:
> > Hello there,
> >
> > If you have a small to medium size web site then go to GoDaddy. Do not
> > believe all that you see from php_info(). I will give you an example. The
> > memory_limit it gives on shared hosting does not reflect the one intended
> > for your shared account. It shows what was set for overall use. But
> blocking
> > php_info() isn't right (at least I don't think so).
>
> Please don't top-post in addition to giving incorrect information like
> this.
>
> --
> 
> Network Infrastructure Manager
> Documentation, Webmaster Teams
> http://www.php.net/
>


Re: [PHP] Common session for all subdomains?

2010-12-21 Thread Ravi Gehlot
Daniel,

Good info.

Ravi.


On Tue, Dec 21, 2010 at 10:23 AM, Daniel Brown  wrote:

> On Tue, Dec 21, 2010 at 02:27, Ravi Gehlot  wrote:
> > That's a good question.
> >
> > There should be a setting on php.ini to allow cross session.
>
> Right.  Because who needs to teach folks about computer security
> when we can just disable it for them anyway?
>
>Like Jonathan pointed out, it's a matter of adjusting the cookie
> parameters to match wildcard subdomains by preceding the part of the
> domain (usually the SLD, but some ccTLD or FQDN situations can be
> different) with a dot, like so:.example.com
>
> --
> 
> Network Infrastructure Manager
> Documentation, Webmaster Teams
> http://www.php.net/
>


Re: [PHP] Re: Session problem

2010-12-21 Thread Ravi Gehlot
Walter,

Session variables may be using cookies which in turn create temp files for
storing such cookies.

Ravi.


On Tue, Dec 21, 2010 at 11:32 AM, Walter Caielli
wrote:

> I've fixed the problem.
> I don't know why, but suddenly windows prevents PHP from writing into
> C:\windows\temp directory.
> Moving the session and log files to another directory solved the problem.
> Until few days ago it worked. I've now to discovered what was changed in
> windows configuration.
>
>
>
> ""Walter Caielli""  ha scritto nel messaggio
> news:bd.40.31041.b7a60...@pb1.pair.com...
> > I'm facing the following basic problem:
> >
> > I have made two simple sample files to explain it:
> >
> > 1st file:
> >  >   session_start();
> >$_SESSION['SS_user'] = "user000";
> >   echo $_SESSION['SS_user'];
> >   echo SID;
> >   echo "".session_id();
> >   echo 'page 1';
> > ?>
> >
> > 2nd file
> >  >   session_start();
> >   echo "file Home";
> >   echo session_name().'+'.session_id();
> >   echo $_SESSION['SS_user'];
> > ?>
> >
> > $_SESSION seems to be empty. Nothing is print. Session Name and session
> ID
> > are the same but it seems that $_SESSION is not shared across the two
> > files. No HTML is made before sessioni_start().
> > Why?
> > I'm using PHP 5.3.4 on IIS, windows XP SP3. Tested as localhost or from
> > another PC inside a LAN.
> >
> > Many thanks
> > Walter
> >
> >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Problem with Include

2010-12-21 Thread Ravi Gehlot
Hello,

Good points. If you are getting paid to do that then fine. There is a
difference between enhancing code and wasting time. I do my best to come up
with the best I can. I always take notes to perform better in upcoming
projects. It is imperative to make good use of time. Unless it is a security
issue, no need to waste time. Again, if you are getting paid for it then
fine. People tune cars for a reason, they want the attention or the thrill.
If you want to tune your code for fun then nobody is against that either :)

Ravi.


On Tue, Dec 21, 2010 at 1:28 PM, a...@ashleysheridan.co.uk <
a...@ashleysheridan.co.uk> wrote:

> (Apologies for top posting; on my mobile just now.)
>
> Not true. Refactoring code is one of the main tasks of a developer. None of
> us produce perfect code, and some code is less perfect than other code. It's
> instinct to want to fix bad code when we're maintaining it or having to add
> new features to it.
>
> For the same reason car enthusiasts tinker with and tune their cars, good
> developers will do the same with code, be it in the form of consolidating
> common code to include files or other ways. To not do so seems to me to
> avoid ones nature really!
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
> - Reply message -
> From: "Ravi Gehlot" 
> Date: Tue, Dec 21, 2010 18:12
> Subject: [PHP] Problem with Include
> To: "Paul M Foster" 
> Cc: 
>
>
> If something is working and you don't know exactly whats under the hood
> then
> you are wasting your time in trying to re-invent your own wheel and waste
> your time and resources to modify something that isn't needed to be
> touched.
> Good programmers make good use of their time as well. We need to keep in
> check with new technology, learn new trends and also master our weakness.
> If
> we keep changing this or that or moving that or this then oh well...there
> goes 1 day worth of work to figure stuff out.
>
> Just my take on this. If you think different, then no problems.
>
> Regards,
> Ravi.
>
>
> On Tue, Dec 21, 2010 at 10:23 AM, Paul M Foster  >wrote:
>
> > On Tue, Dec 21, 2010 at 02:35:33AM -0500, David Hutto wrote:
> >
> > > On Tue, Dec 21, 2010 at 2:29 AM, Ravi Gehlot 
> > wrote:
> > > > Why mess with something that is already working? If you are trying to
> > make
> > > > it pretty then you are not solving a problem. You are creating one.
> > >
> > >
> > > Define working. I've had programs 'work', but more experienced would
> > > say it's flawed in some respect. Does it perform the immediate task?
> > >
> > > Now define pretty. Is it aesthetically pleasing to you, or to someone
> > > else with less, or maybe more experience.
> > >
> > > By defining the two above, you then define whether it's a problem. To
> > > you, or to them, or to the original designer?
> >
> > Beware of "more experienced" programmers. I recently talked to an
> > ex-boss of mine who had a programmer flake out on him. One of his
> > customers threatened to take this flaky code to another company and get
> > their opinion about whether it was good code or not. My ex-boss
> > explained that, of course, they'd shoot it down. Because that's what
> > programmers do-- they complain about other programmers' code. I'd never
> > heard that idea expressed aloud. But when I thought about it, I realized
> > it was true. Hell, look at the content of this list. ;-}
> >
> > Paul
> >
> > --
> > Paul M. Foster
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>


Re: [PHP] Re: Warning when calling session_start()

2010-12-22 Thread Ravi Gehlot
session_start (); should be before everything...first thing in the page.

Ravi.


On Wed, Dec 22, 2010 at 12:51 AM,  wrote:

> Hi, folks,
>
> On Tue, 21 Dec 2010 21:35:17 -0800 [06:35:17 AM CET],
> Michael Shadle  wrote:
>
> > first - this is probably your culprit:
> > don't output empty lines before you do
> > anything (just a general good practice)
>
> Whow! This did the trick !
>
> Warning vanished when I changed beginning of
> script to:
>
> 1  2
>
> I wasn't aware that the HTML comment and the
> following empty line are in fact written to
> output.  But that's clear now  :-)
>
> So I suppose my local PHP setup supressed this
> warning or is more compliant ...
>
> > also i'd turn on output buffering.
>
> Since it worked without warning at 1st try,
> I haven't changed output buffering (yet).
>
> Mike, many thanks for Your PROMPT and HELPFUL
> answer! Have a nice day!
>
> Rolf
> --
> Dipl.phys. Rudolf Otto Blättner,
> D 91074 Herzogenaurach, Germany.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] empty() in email message

2010-12-22 Thread Ravi Gehlot
Hello Gary,

Please research the difference between a single quote and a double quote.
Also, you can use the operator .=(dot + equal) in this manner:

if(!empty($_POST['fname'])) {
$msg .= "$lname\n";
} else if(!empty($_POST['lname'])) {
$msg .= "$lname\n";
}



On Tue, Dec 14, 2010 at 12:04 AM, Gary  wrote:

>
> ""Daevid Vincent""  wrote in message
> news:7d7c84d94dd24035a620e68b5b937...@mascorp.com...
> >> - Original message -
> >> From: Gary 
> >> To: php-general@lists.php.net 
> >> Date: Monday, December 13, 2010, 7:47:49 PM
> >> Subject: [PHP] empty() in email message
> >>
> >> I have an email message
> >>
> >> $msg =  'Name: $fname ' . ' $lname\n'
> >> . "Phone: $phone\n"
> >> . "Email: $email\n"
> >>
> >> and it works fine, however in this message there are about 30
> >> variables that
> >> are being called...as such
> >>
> >> . "Order: beefschnitzel $beefschnitzel\n"
> >> . "Order: beefstrips $beefstrips\n"
> >> . "Order: cheesesausage $cheesesausage\n"
> >> . "Order: crumbedsausage $crumbedsausage\n"
> >> . "Order: chucksteak $chucksteak\n"
> >> . "Order: cornedbeef $cornedbeef\n"
> >> . "Order: dicedsteak $dicedsteak\n"
> >> . "Order: filletmignon $filletmignon\n"
> >>
> >> I want to only send the message if the submitter enters an
> >> amount in the
> >> form for the corresponding variable, instead of having a
> >> bunch of empty
> >> messages.  So I have been trying to use the empty() function as such:
> >>
> >> . if empty($beefolives){''} elseif (isset($beefolives)) {
> >> 'Order: beefolives
> >> $beefolives\n'}
> >
> > You are setting this up fundamentally wrong.
> >
> > You should be using an array and looping through it.
> >
> > Something like:
> >
> > $myorder['cowface'] = 1;
> > $myorder['beefenweiner'] = 2;
> > $myorder['chucksteak']   = 1;
> >
> > foreach ($myorder as $item => $quantity)
> > {
> > echo "Order: $item x $quantity\n";
> > }
> >
> > Then your array only contains the items someone actually puchased and how
> > many.
> >
> > d
> >
>
> Daevid
>
> I knew someone was going to point out this was a convoluted method, and I
> agree.  This was sent to me by someone that needed to make the mail form
> work.  My suggestion was to look into a pre-made shopping cart, however
> that
> was not going to work for them, so I made the mail() work for them.
>
> I had thought about putting it into an array, but had not gotten that far
> into it.  I will look over the code to see how it works.
>
> Thank you for your help.
>
> gary
>
>
>
>
> __ Information from ESET Smart Security, version of virus signature
> database 5700 (20101213) __
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] accessing magic parent set

2010-12-22 Thread Ravi Gehlot
Hello,

$this only calls variables inside of a method. In your function, you are
calling a variable that was defined inside of your function called
$columnName. You should past the whole class. Not just the methods.

"The pseudo-variable $this is available when a method is called from within
an object context. $this is a reference to the calling object (usually the
object to which the method belongs, but possibly another object, if the
method is called statically from the context of a secondary object). " taken
from http://www.php.net/manual/en/language.oop5.basic.php

The parent keyword indicates that this is an extended class. You are
referring back to the master class.

Ravi.


On Wed, Dec 22, 2010 at 9:35 AM, Alexandru Patranescu wrote:

> Is this the only way to access the magic __set from the parent class:
>
>public function __set($columnName, $value)
>{
>if ($value !== $this->$columnName) {
>parent::__set($columnName, $value);
>}
>}
>
>
> I would have liked to work this way:
>
>public function __set($columnName, $value)
>{
>if ($value !== $this->$columnName) {
>parent::$columnName = $value;
>}
>}
>
>
> And another question.
> There is a self, a static and a parent
> Why is it only $this and not a $parent too?
>


Re: [PHP] Stripslashes

2010-12-22 Thread Ravi Gehlot
What are these magic quotes anyways?. What are they used for? escaping?

Regards,
Ravi.

On Tue, Nov 16, 2010 at 11:44 PM, Adam Richardson wrote:

> On Tue, Nov 16, 2010 at 10:10 PM, Gary  wrote:
>
> > I was doing a test of stripslashes on a $_POST, when I recieved the
> email,
> > all of the slashes were still in the data posted.
> >
> > I used :
> >
> > $fname = stripslashes($_POST['fname']);
> >
> > I input G\\a//r\y\\, and was expecting, according to the manuel
> G\a//r*y\,
> > but got the original spelling.
> >
>
> In this case, you should get the original, if I'm understanding correctly.
>  Think of it like a basic math problem:
>
> Step 1: Happens automatically when you submit the form and PHP receives the
> form variables
> input + slashes = slashed_input
>
> Step 2: This happens when you call stripslashes.
> slashed_input - slashes = input
>
> The goal of stripslashes is that it will undo what happened automatically
> using magic_quotes_gpc (which essentially calls addslashes on the GPC vars
> behind the scenes) so you'll end up with the original input.
>
> So, working through your example:
>
>   1. You inputted into a form G\\a//r\y\\ and submitted the form.
>   2. PHP received G\\a//r\y\\ and added slashes (Ga//r\\y).
>   3. You called stripslashes (G\\a//r\y\\).
>
>
>
>
> >
> > I added:
> >
> > echo stripslashes($fname); and did get the expected result on the page,
> but
> > not in the email from the $_POST.
> >
>
> Here, you called stripslashes on something already stripped once, so you
> now
> have a new value (G\a//ry\).
>
>
> >
> > I also tried
> >
> > $fname = (stripslashes($_POST['fname']));
> >
>
> This would be no different than your attempt without enclosing parentheses.
>
> Now, let me just say that I detest magic_quotes, and it's best to run with
> them disabled so you  don't even have to worry about this kind of issue
> (they've been deprecated.)  But, perhaps you were just trying to learn
> about
> some piece of legacy code.
>
> Hope the explanation helps, Gary.
>
> Adam
>
> --
> Nephtali:  PHP web framework that functions beautifully
> http://nephtaliproject.com
>


Re: [PHP] [SOLVED] Re: Upgraded system and now $_SERVER['SERVER_NAME'] is not more working

2010-12-22 Thread Ravi Gehlot
You probably have error_reporting turned on and that caught on errors. There
are new tougher rules/requirements with newer PHP versions.

Ravi.


Re: [PHP] Stripslashes

2010-12-22 Thread Ravi Gehlot
On Wed, Dec 22, 2010 at 3:34 PM, Bob McConnell  wrote:

> From: Ravi Gehlot
>
> > What are these magic quotes anyways?. What are they used for?
> escaping?
>
> I wasn't there at the time, but I gather that the general idea was to
> automagically insert escape characters into data submitted from a form.
> However, they used a backslash as the escape character, which is not
> universally recognized across database engines. Even the SQL standard
> defines an escape as a single quote character.
>
> We used to have magic quotes enabled, and came up with the following
> code to clean up the mess it caused.
>
>// If magic quotes is on, we want to remove slashes
>if (get_magic_quotes_gpc()) {
>  // Magic quotes is on
>  $response = stripslashes($_POST[$key]);
>} else {
>  $response = $_POST[$key];
>}
>
> For future releases of PHP, this will also need a check to see if
> get_magic_quotes_gpc() exists first.
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Bob,

Thank you very much. This is good information. What I found out from
http://us2.php.net/manual/en/function.stripslashes.php was the following:
"An example use of *stripslashes()* is when the PHP directive
magic_quotes_gpc<http://us2.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc>is
*on* (it's on by default), and you aren't inserting this data into a place
(such as a database) that requires escaping. For example, if you're simply
outputting data straight from an HTML form. "

So that means that stripslashes() isn't intended for DB insertions but only
straight output. So I will remove it from my code.

Thanks,
Ravi.


Re: [PHP] Stripslashes

2010-12-22 Thread Ravi Gehlot
On Wed, Dec 22, 2010 at 4:21 PM, Russell Dias  wrote:

> stripslashes() is rife with gaping security holes.  For mysql
> insertion rely on mysql_real_escape_string() or alternatively, you can
> use prepared statements.
>
> For outputting data on the page you should ideally be using
> htmlspecialchars($var, ENT_QUOTES);
>
> cheers,
> Russ
>
> On Thu, Dec 23, 2010 at 6:48 AM, Ravi Gehlot  wrote:
> > On Wed, Dec 22, 2010 at 3:34 PM, Bob McConnell  wrote:
> >
> >> From: Ravi Gehlot
> >>
> >> > What are these magic quotes anyways?. What are they used for?
> >> escaping?
> >>
> >> I wasn't there at the time, but I gather that the general idea was to
> >> automagically insert escape characters into data submitted from a form.
> >> However, they used a backslash as the escape character, which is not
> >> universally recognized across database engines. Even the SQL standard
> >> defines an escape as a single quote character.
> >>
> >> We used to have magic quotes enabled, and came up with the following
> >> code to clean up the mess it caused.
> >>
> >>// If magic quotes is on, we want to remove slashes
> >>if (get_magic_quotes_gpc()) {
> >>  // Magic quotes is on
> >>  $response = stripslashes($_POST[$key]);
> >>} else {
> >>  $response = $_POST[$key];
> >>}
> >>
> >> For future releases of PHP, this will also need a check to see if
> >> get_magic_quotes_gpc() exists first.
> >>
> >> Bob McConnell
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> > Bob,
> >
> > Thank you very much. This is good information. What I found out from
> > http://us2.php.net/manual/en/function.stripslashes.php was the
> following:
>
> "An example use of *stripslashes()* is when the PHP directive
> > magic_quotes_gpc<
> http://us2.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc
> >is
> > *on* (it's on by default), and you aren't inserting this data into a
> place
> > (such as a database) that requires escaping. For example, if you're
> simply
> > outputting data straight from an HTML form. "
> >
> > So that means that stripslashes() isn't intended for DB insertions but
> only
> > straight output. So I will remove it from my code.
> >
> > Thanks,
> > Ravi.
> >
>

Hello Russell,

When you use htmlspecialchars() it tries to escape single/double quotes with
a bunch of backslashes. I had stripslashes() in an attempt to try to get the
backslashes away but it didn't. So the solution was to disable magic quotes
in php.ini. With GoDaddy shared hosting, I had to rename php.ini over to
php5.ini in order to have this to work. Also had to include the command like
responsible for disabling magic quotes. Everything is good and clean now.

Now you type for example "Hunter's Reserve Circle" and it keeps it as it is.
Before it would print something like "Hunter'///s Reserve Circle".
With double quote, the situation would be even worse.

mysql_real_escape_string() is a must in order to avoid SQL injections.

Regards,
Ravi.


Re: [PHP] static Logging class?

2013-03-03 Thread Ravi Gehlot
Hello Lars,

I would apply the Singleton Pattern where you would have 1 instance for you
entire application. As far as whether or not to use a static method, I
would weigh the options. If you just want to call a method that you know
will not have to be changed in the future and that method will not be using
any pre-defined properties, then it makes sense to call a static method.
Bear in mind that static methods can not be overridden.

Best of luck,

-
  [image: logo]
*Ravi Gehlot
*
Mobile: 407-283-5282
Orlando, FL 32765-8085
http://www.RaviGehlot.Net/
https://github.com/ravigehlot

*"First, solve the problem. Then, write the code."*
[image: Twitter] <http://www.twitter.com/ravigehlot> [image:
LinkedIn]<http://www.linkedin.com/in/ravigehlot> [image:
Amazon]<https://www.amazon.com/gp/pdp/profile/A35NGY72YZSFR7?ie=UTF8&ref_=ya_56>
[image:
Meetup] <http://www.meetup.com/members/12029903/> [image:
pinterest]<http://pinterest.com/ravigehlot/> [image:
reddit] <http://www.reddit.com/user/ravigehlot/>
Contact me: [image: Google Talk] ravigehlot [image: Skype] ravigehlot [image:
Y! Messenger] ravigehlot


On Sun, Mar 3, 2013 at 8:26 AM, Lars Nielsen  wrote:

> Hi,
>
> I work on a little hobby-project, and i want to make a oo logging
> facility. (php5.3 oop)
>
> Is it best to make a class with static functions that i can call from my
> other classes? Or is it more appropriate to make a real logging-class i
> should instantiate every time i need to log something? (I just want to
> log to a file)
>
> Best regards
> Lars Nielsen
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] static Logging class?

2013-03-03 Thread Ravi Gehlot
Hello Larry,

Thanks for sharing!



-
  [image: logo]
*Ravi Gehlot
*
Mobile: 407-283-5282
Orlando, FL 32765-8085
http://www.RaviGehlot.Net/
https://github.com/ravigehlot

*"First, solve the problem. Then, write the code."*
[image: Twitter] <http://www.twitter.com/ravigehlot> [image:
LinkedIn]<http://www.linkedin.com/in/ravigehlot> [image:
Amazon]<https://www.amazon.com/gp/pdp/profile/A35NGY72YZSFR7?ie=UTF8&ref_=ya_56>
[image:
Meetup] <http://www.meetup.com/members/12029903/> [image:
pinterest]<http://pinterest.com/ravigehlot/> [image:
reddit] <http://www.reddit.com/user/ravigehlot/>
Contact me: [image: Google Talk] ravigehlot [image: Skype] ravigehlot [image:
Y! Messenger] ravigehlot


On Sun, Mar 3, 2013 at 1:48 PM, Larry Garfield wrote:

> Make a real classed object that you pass to various objects that need it.
>  Otherwise you make your life way harder for unit testing.  Don't have a
> class that self-enforces that it's a singleton.  That way lies pain.
>
> In particular, I recommend using or writing a class based on the PSR-3
> recommendation:
>
> https://github.com/php-fig/**fig-standards/blob/master/**
> accepted/PSR-3-logger-**interface.md<https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md>
>
> There's even stock code for the interface and some useful base classes
> available:
>
> https://packagist.org/**packages/psr/log<https://packagist.org/packages/psr/log>
>
> And for added fun, there are already publicly available open source
> libraries that implement PSR-3 that you can just drop in and use, such as:
>
> https://packagist.org/**packages/monolog/monolog<https://packagist.org/packages/monolog/monolog>
>
> (If that's too heavy for you, writing your own PSR-3 compatible logger is
> dead-simple.)
>
>
> I'm sure you're about to say "zOMG this is just a hobby project, I don't
> need something that fancy and all injected and shit!"  If it's a simple
> project, use a simple container to do all the hard work for you:
>
> https://packagist.org/**packages/pimple/pimple<https://packagist.org/packages/pimple/pimple>
>
> (That's < 100 lines of executable code.  Quite powerful, dead simple to
> use.)
>
> Cheers.
>
> --Larry Garfield, FIG member
>
>
>
> On 03/03/2013 07:26 AM, Lars Nielsen wrote:
>
>> Hi,
>>
>> I work on a little hobby-project, and i want to make a oo logging
>> facility. (php5.3 oop)
>>
>> Is it best to make a class with static functions that i can call from my
>> other classes? Or is it more appropriate to make a real logging-class i
>> should instantiate every time i need to log something? (I just want to
>> log to a file)
>>
>> Best regards
>> Lars Nielsen
>>
>>
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Introduction ... !

2013-03-03 Thread Ravi Gehlot
Hello Nick,

Welcome to the list. I joined the list awhile back then unsubscribed for
no apparent reason. This list was very active years ago. I came back about
a few months ago just as a watcher. I didn't really post or participate at
all. I guess, there are a lot of watchers "only" people here. They receive
digest e-mails; they just don't participate in any way. Then, there are
those who lost their jobs due to the recession and so they dropped off the
list as well. There are a lot of developers unemployed. I would imagine
that other developers didn't keep up with the changes. PHP has come a long
way as far as Object Oriented Programming is concerned. There have been
many discussions about Design Patterns and extending existing classes. So a
lot has changed in the last 5 years.

I do believe that the list will pick up again.

Welcome back,
Ravi.

On Fri, Mar 1, 2013 at 10:57 AM, Nick Whiting  wrote:

> Hello PHP'ers!
>
> Just thought I would introduce myself to the mailing list since I've worked
> with PHP for almost 10 years now and yet haven't really been community
> active ...
>
> I've developed quite a few open-source projects over the years that I hope
> someone here will find as useful as I have ... they are all hosted on
> Github @prggmr.
>
> XPSPL - Signal Processor in PHP
> docpx - PHP Documentation Generator for Sphinx
>
> Again Hello Everyone!
>
> Cheers!
> --
> Nickolas Whiting - prggmr.org
>  - Remember to write less code that does more faster -
>


Re: [PHP] [ad] [free+opensource] htmlMicroscope (nested array viewer/dumper) upgraded - now allows for even larger arrays

2013-03-04 Thread Ravi Gehlot
I like PHPUnit for that matter. It does a good job of debugging.

Ravi.


On Sat, Dec 22, 2012 at 8:41 AM, rene7705  wrote:

> Hi Folks.
>
> URL: http://fancywebapps.com/products/htmlMicroscope
>
> Just wanted to let you all know that I've completed a long overdue
> upgrade to my free htmlMicroscope web component.
> It is basically a fancy replacement for var_dump() which can show you
> the full depth of an array regardless of how large or deep your PHP
> array or javascript object is.
>
> I won't repeat the entire homepage content here, but I think this
> version could be useful for at least some of the programmers on this
> list.
>
> I'll only repeat this message for significant updates.
>
> This is a significant update because I've finally cracked the barrier
> of displaying an object with more than a few hundred key-value pairs
> on a single level. That used to crash all browsers, not anymore.
>
> i'll continue work on this, want to build in (in order of priority):
> - auto navigation options (auto smooth scroll to links within the data)
> - middle mouse button click -> smooth offset scrolling
> - html source view
> - auto indented and colorcoded syntax-checked view for html + json
>
> Merry Christmas and a productive New Year to ya'll :D
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Accessing Files Outside the Web Root

2013-03-14 Thread Ravi Gehlot
Hello Dale,

The spiders are not the only problem. The issue here is that anyone can
download your files from your website and then make them available
elsewhere. In order to address the problem, you should create a "Members
Restricted Area" where members only could download your files. You can then
make your PDF directory only visible through your Members Restricted Area.
That directory would be invisible to the web. In some Linux distros, if the
file/directory is not a member of www-data, it is not visible online. But
you can still link the files to your PHP page.

Ravi.

On Wed, Mar 13, 2013 at 4:38 PM, Dale H. Cook
wrote:

> Let me preface my question by noting that I am virtually a PHP novice.
> Although I am a long-time webmaster, and have used PHP for some years to
> give visitors access to information in my SQL database, this is my first
> attempt to use it for another purpose. I have browsed the mailing list
> archives and have searched online but have not yet succeeded in teaching
> myself how to do what I want to do. This need not provoke a lengthy
> discussion or involve extensive hand-holding - if someone can point to an
> appropriate code sample or online tutorial that might do the trick.
>
> I am the author of a number of PDF files that serve as genealogical
> reference works. My problem is that there are a number of sites which are
> posing as search engines and which display my PDF files in their entirety
> on their own sites. These pirate sites are not simply opening a window that
> displays my files as they appear on my site. They are using Google Docs to
> display copies of my files that are cached or stored elsewhere online. The
> proof of that is that I can modify one of my files and upload it to my
> site. The file, as seen on my site, immediately displays the modification.
> The same file, as displayed on the pirate sites, is unmodified and may
> remain unmodified for weeks.
>
> It is obvious that my files, which are stored under public_html, are being
> spidered and then stored or cached. This displeases me greatly. I want my
> files, some of which have cost an enormous amount of work over many years,
> to be available only on my site. Legitimate search engines, such as Google,
> may display a snippet, but they do not display the entire file - they link
> to my site so the visitor can get the file from me.
>
> A little study has indicated to me that if I store those files in a folder
> outside the web root and use PHP to provide access they will not be
> spidered. Writing a PHP script to provide access to the files in that
> folder is what I need help with. I have experimented with a number of code
> samples but have not been able to make things work. Could any of you point
> to code samples or tutorials that might help me? Remember that, aside from
> the code I have written to handle my SQL database I am a PHP novice.
>
> Dale H. Cook, Member, NEHGS and MA Society of Mayflower Descendants;
> Plymouth Co. MA Coordinator for the USGenWeb Project
> Administrator of http://plymouthcolony.net
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Re: [PHP-DEV] PHP 5.5.0 final has been released!

2013-06-21 Thread Ravi Gehlot
Awesome!


On Thu, Jun 20, 2013 at 11:14 PM, Marco Pivetta  wrote:

> Well done! Congratulations!
> On 20 Jun 2013 23:23, "Julien Pauli"  wrote:
>
> > Hello!
> >
> > The PHP Development Team would like to announce the immediate release of
> > PHP 5.5.0. This release includes a large number of new features and bug
> > fixes.
> >
> > A separate release announcement is also available. For changes in PHP
> > 5.5.0 since PHP 5.4, please consult the PHP 5 ChangeLog.
> >
> > Release Announcement: http://www.php.net/release_5_5_0.php
> > Downloads:http://www.php.net/downloads.php#v5.5
> > Changelog:http://www.php.net/ChangeLog-5.php#5.5.0
> >
> > Thanks to all contributors that made this new version available.
> >
> > regards,
> >
> > David Soria Parra & Julien Pauli
> >
>


[PHP] Accessing env variables

2005-04-01 Thread Ravi Natarajan
Hi,

 

I have defined couple of environment variables in one of my apache
module using setenv() at fixups and handler function calls.

 

I have another php module, where I need to access these variables. So I
have defined these variables as "global $var1, $var2 ..etc";

 

When I try to access these variables as $var1 and $var2 , they don't
seem to be set, so I am not getting correct values, but they give
correct values when I acess them using getenv() call.

 

I thought that the global command would make the global environment
variables available in the local php code.

 

How to access these environment variables in my php code without using
getenv() call.

 

Thanks

 

Ravi Natarajan

 

 



[PHP] Safe mode effect

2004-04-22 Thread Ravi kumar


HI,

goole.com found so many details about safe mode too much to understand.

My hosting provider set php safe mode = enable . so iam unable to use so

many scripts .

can any one give good free image gallery software which will work under

safe mode = enable .

is it true that with apache 2.x version , we can get ride of php safe mode ?

- thanks for your time



-- 
Knowledge is power share it - http://ravikumar.info

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



[PHP] php.ini include_path and symlinks

2007-11-06 Thread Ravi Menon
Hi,

We run php 5.2.0 + apache 2.2. with apc turned on ( apc.stat also on
). Earlier we did not use the php.ini include_path setting. We relied
on some symlinks for our common code
so that require_once works correctly.

This worked fine and during code releases we flipped the main
'release' symlink atomically, without restarting apache.

Later we decided to use php.ini include path to refactor common code
more cleanly and it looks like:

include_path=.:/some/dir/current:..

Now 'current' above is a symlink.

When we push out a new release the current is updated atomically and
apache is not restarted.

This seems to pick the new changes and I ran some manual tests to
confirm. However occasionally I see weird
errors where it seems php could be resolving the symlink to the actual
dir. at apache startup, and it assumes
that old dir. When a new release goes out, we see 'fatal redeclare errors' etc..

Restarting apache (TERM and not USR1) seems to fix it.

We could update our install scripts to restart apache, but I am just
curious, is this really necessary?

Is there anyway to prevent php from not resolving symlinks but use
them as it is in the include_path?

Thanks,
Ravi

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



Re: [PHP] php.ini include_path and symlinks

2007-11-07 Thread Ravi Menon
>
> Are you using a compile cache like eaccelerator or APC etc? Sometimes
> it's the cache that doesn't realize things have changed. I use a symlink
> switcher for version releases also and I always flush the eaccelerator
> directory when I do that.
Yes we use APC ( with apc.stat on ). This was the case even before we introduced
include_path, but earlier, all the symlinks were to a relative path (
e.g. libraries ---> ../libs/.. ).

Thanks for the pointer - I will look into this.

Ravi




>
> Cheers,
> Rob.
> --
> ...
> SwarmBuy.com - http://www.swarmbuy.com
>
> Leveraging the buying power of the masses!
> ...
>

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



[PHP] apc and cli

2007-12-12 Thread Ravi Menon
Hi,

We have long running daemons written in php ( cli, non-apache
contexts) with the typical pattern:

while( !$shutdown )
{
$c = new SomeClass;

$c->process();
}

For performance reasons, would it help if apc.enable_cli is turned on:

  apc.enable_cli  integer

Mostly for testing and debugging. Setting this enables APC for the
CLI version of PHP. Normally you wouldn't want to create, populate and
tear down the APC cache on every CLI request, but for various test
scenarios it is handy to be able to enable APC for the CLI version of
APC easily.


I am slightly confused by the statement - 'Mostly for testing and
debugging.' .

On each loop iteration, does php recompile the code in 'SomeClass' (
and all its dependencies ) or it is really cached ( as it has seen the
class code once ).

If there is a php internals document on such issues, do let me know.

Thanks,
Ravi

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



Re: [PHP] apc and cli

2007-12-12 Thread Ravi Menon
Thanks for clarifying my doubts - the steps below sounds right to me.

I was just considering the overall perf. of such php daemons and
whether we can get some free perf. boost
with that apc setting.

Ravi


On Dec 12, 2007 12:19 PM, Richard Lynch <[EMAIL PROTECTED]> wrote:
>
> On Wed, December 12, 2007 1:33 pm, Ravi Menon wrote:
> > We have long running daemons written in php ( cli, non-apache
> > contexts) with the typical pattern:
> >
> > while( !$shutdown )
> > {
> > $c = new SomeClass;
> >
> > $c->process();
> > }
> >
> > For performance reasons, would it help if apc.enable_cli is turned on:
> >
> >   apc.enable_cli  integer
> >
> > Mostly for testing and debugging. Setting this enables APC for the
> > CLI version of PHP. Normally you wouldn't want to create, populate and
> > tear down the APC cache on every CLI request, but for various test
> > scenarios it is handy to be able to enable APC for the CLI version of
> > APC easily.
> >
> >
> > I am slightly confused by the statement - 'Mostly for testing and
> > debugging.' .
> >
> > On each loop iteration, does php recompile the code in 'SomeClass' (
> > and all its dependencies ) or it is really cached ( as it has seen the
> > class code once ).
> >
> > If there is a php internals document on such issues, do let me know.
>
> The following is almost-for-sure correct, but I wouldn't swear in
> court...
>
> Step 0. Read PHP/HTML source code.
> Step 1. PHP uses a 2-pass compiler and generates byte-code.
> Step 2. The byte-code is then feed to the executer.
> Step 3. Executer spews output (or crashes or whatever)
>
> APC and other caches add a Step 1A., which stores the byte-code in RAM
> under the filename (or full path, depending on config) as a key.
>
> Therefore, adding APC will not affect in any way the "while" loop --
> It's compiled once in Step 1, and that's it.
>
> If you re-run the same script again and again, however, APC in CLI
> might be able to keep the script around and avoid a hit to the disk to
> LOAD the script (Step 0 above) as well as avoiding the 2-pass
> compilation to byte-code (Step 1 above).
>
> NOTE:
> Step 0 is the REALLY expensive step where APC et al are REALLY
> boosting performance.
>
> APC et al *could* just insert step 0A and store the PHP source, and
> have ALMOST the same benefits.
>
> However, storing the compiled version at Step 1A gets you some free
> gravy in not re-compiling the PHP source to byte-code, so they do that
> because, well, it's essentially FREE and saves a few more cpu cycles.
>
> But the REAL boost, again, is from not hammering the hard drive (slow)
> to load PHP source into RAM, Step 0.
>
> PS
> If you are really concerned about the constructor of SomeClass being
> expensive, time it and see.
>
> YOU may be doing something incredibly expensive there like
> re-connecting to the database (slow!) each time.
>
> You may also not even NEED a whole new SomeClass every time -- Perhaps
> you could just make a singleton and then reset its values and call
> process() with the new values instead of building up a whole new
> instance each time.
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/from/lynch
> Yeah, I get a buck. So?
>
>

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



[PHP] curl timeout vs socket timeout

2008-01-28 Thread Ravi Menon
Hi,

We have two versions of client code, one using curl, and other one
using raw sockets via fsockopen(), and
we use the following code to set the i/o timeouts:

1) curl:

.
.
curl_setopt( $handle, CURLOPT_TIMEOUT, 1 );
.
.
$resp = curl_exec($handle)


2) sockets:

stream_set_timeout( $sock, 1);

Here we use frwrite() and fread() to send the request and read the
response respectively.


In (1),  how is the timeout applied - is it:

a) timeout includes the entire curl_exec() call - the combined socket
write()  ( to send the request ) and
the  read() ( read the response ) calls.

or

b) timeout is independently applied to write() and read() end respectively.

Some of our tests seem to indicate it is (a).


In (2), I am assuming the stream timeout is applied at each i/o call
independently for fwrite() and fread() - I am pretty
much certain on this as this is how it would map to underlying C calls.


It will be good to get a confirmation on our doubts.

Thanks,
Ravi

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



Re: [PHP] System errno in PHP

2008-02-22 Thread Ravi Menon
Hi,

I also ran into the same issue with file and socket apis, and for now, I just
hack it like ( for linux 2.6 systems ):

class Errno
{
  const EINTR=  4;
  const EIO  =  5;
  const EINVAL   =  22;
  const ENODATA  =  61;
  const EBADMSG  =  74;
  const EOPNOTSUPP   =  95;
  const ECONNRESET   =  104;
  const ENOTCONN =  107;
  const ETIMEDOUT=  110;
  const EALREADY =  114;
  const EINPROGRESS  =  115;

  // useful static methods that use posix_strerror()
  // and socket_strerror() to return strings for logging purposes...
  .
  .

}

Clearly this is not portable, but I am betting that usually on the
same kernel releases, they
don't usually change these numbers around.

Having PHP expose these useful constants in a portable manner would be
a big plus.

Thanks,
Ravi


On Thu, Feb 21, 2008 at 9:04 AM, Richard Lynch <[EMAIL PROTECTED]> wrote:
> On Wed, February 20, 2008 2:56 am, Michal Maras wrote:
>  > I have read http://php.net/fopen from top to bottom, but I could not
>  > find
>  > how to get  system error number.
>  > With set_error_handler I can get string for example
>  >
>  > fopen(hmc_configuration.cfg)
>  > 
> [function.fopen<http://ds63450.mspr.detemobil.de/%7Emmaras/HMC/function.fopen>]:
>  > failed to open stream: Permission denied
>  >
>  > but I need integer number not string, because string error messages
>  > depends
>  > on locale setting.
>  >  Of course, I can test some conditions before fopen, but it is not
>  > enough
>  > for me.
>
>  Put in a Feature Request to expose the error number from the OS, I
>  guess...
>
>  http://bugs.php.net/
>
>  It *seems* like it ought to be reasonable enough to this naive user.
>
>
>  --
>  Some people have a "gift" link here.
>  Know what I want?
>  I want you to buy a CD from some indie artist.
>  http://cdbaby.com/from/lynch
>  Yeah, I get a buck. So?
>
>  --
>
>
> PHP General Mailing List (http://www.php.net/)
>  To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



[PHP] call to pprofp not working for PHP APD

2006-06-12 Thread Ravi Jethwa
Hello,

 

I was wondering if somebody could provide some advice on where I might
be going wrong if I am receiving the following error:

 

"bash: /usr/bin/pprofp: /usr/local/bin/php: bad interpreter: No such
file or directory".

 

When I try to call the pprofp program in order to format the profile
data using APD.

 

Thanks for you help.  


Ravi Jethwa
OPUS MEDIA PLC - Developer 

t

+44 (0)845 122 3180

f

+44 (0)845 122 3190

e

[EMAIL PROTECTED]

w

www.opusmediaplc.com

a

4th Floor, 24 Buckingham Gate, London, SW1E 6LB

 



This email and its attachments are intended solely for the addressee.
Any views or opinions presented are those of the originator, unless
otherwise stated, and do not necessarily represent those of Opus Media
plc. If you received this in error, please notify us immediately and
then delete the email and any copies of it. If you are not the intended
recipient, please note that any distribution, copying or use of this
information is strictly prohibited.

 



[PHP] Redisplaying information from a HTML form

2005-08-10 Thread Ravi Gogna

Hi there

I'm absolutely new at this so forgive me if none of it makes any sense! 
I'm trying to write a page which lets you apply for tickets. I've 
written it in PHP and used simple variable names for all the input 
fields. Upon clicking submit, I want the form to be checked for 
incorrect formats and blank fields.


I've managed to write the checking program in such a way that clicking 
submit launches an 'error' page which displays at the top of the page 
which field is wrong, and then redisplays the form. (The form redisplay 
is done using a function which uses the variables I used in the HTML 
form page). My problem is this: when the 'error' page comes up all of 
the text boxes will quite happily redisplay the data that was put into 
them, but I have a couple of drop-down boxes and radio buttons which 
lose their value. Is there a way I can make these boxes and buttons 
retain their value?


Thanks

Ravi Gogna

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



[PHP] Automatically generated emails

2005-08-29 Thread Ravi Gogna
This is probably a really simple question, but I can't work out what to 
write! I've written a fairly standard HTML form and I would like an 
email to be generated as soon as the user clicks 'Submit'. Can you help?!


Thanks

Ravi Gogna

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



Re: [PHP] Automatically generated emails

2005-08-29 Thread Ravi Gogna
Nice to know that newbies are well looked after on these lists. If you 
didn't wanna help, you could have not clicked reply


Jay Blanchard wrote:


[snip]
Yes.
[/snip]

Watch out, this'll start a flood of "why can't you be nice"? e-mail


John, any relatives still in LA?

 



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



Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?

2010-01-08 Thread J Ravi Menon
Hi,

A note on bytecode caching and include/include_once performance. A
while ago when we were profiling our code, we did notice that file
includes do take a noticeable percentage of overall overhead (enough
for us to look into it more deep). We are using apc cache on a
standard LAMP platform (linux 2.6 series, apache 2.2x and PHP 5
series).

Our includes were using 'relative' paths (e.g.  include_once
'../common/somefile.inc' or include_once 'lib/somefuncs.inc' ) and
within APC cache logic, it resolves such relative paths to absolute
paths via a realpath() calls. This can be fairly file-system intensive
(lots of syscalls like stat() and readlink() to resolve symlinks
etc...). APC uses absolute paths as key into the opcode cache.

This gets worse if it has to find your files via the 'ini_path'
setting (and most of your library or common code is not in the first
component or so ).

So from APC cache perspective, it is most efficient if your include
paths are all absolute (realpath() logic is skipped) - e.g.:

include_once $BASE_DIR . '/common/somefile.inc';
include_once $BASE_DIR . '/lib/somefuncs.inc';

and so on where '$BASE_DIR' could be set via apache Setenv directives
( $_SERVER['BASE_DIR'] or even hardcoded all over the place).

There were other issues with include vs include_once and apc cache,
but I don't recall why there were performance difference (with include
only even with relative paths, the performance was better, but
managing dependencies is to cumbersome).

Not sure how other bytecode cache handles relative paths but I suspect
it has to do something similar.

>From a pure code readability point of view and more automated
dependency management (as close to compiled languages as possible), I
do favor include_once/require_once strategy with absolute path
strategy, but it is not unheard of where to squeeze out maximal
performance, a giant single 'include' is done. Sometimes this is done
on prod. systems where a parser goes through and generates this big
include file, and ensure it is placed somewhere in the beginning the
main 'controller.php' (MVC model) and all other includes stripped off.

Hope this helps in making your decision.

Ravi


On Fri, Jan 8, 2010 at 8:59 AM, Robert Cummings  wrote:
> clanc...@cybec.com.au wrote:
>>
>> On Thu, 07 Jan 2010 22:48:59 -0500, rob...@interjinn.com (Robert Cummings)
>> wrote:
>>
>>> clanc...@cybec.com.au wrote:
>>>>
>>>> Thank you all for your comments. I did not know about bytecode caches.
>>>> They're an
>>>> interesting concept, but if I am interpreting the paper
>>>> http://itst.net/654-php-on-fire-three-opcode-caches-compared correctly
>>>> they only double
>>>> the average speed of operation, which is rather less than I would have
>>>> anticipated.
>>>
>>> I strongly advise that you take the time to try a bytecode cache. Within
>>> linux environments I am partial to eaccelerator. In IIS environments I now
>>> use WinCache from Microsoft. From my own observations with a multitude of
>>> different types of PHP web applications I find that the speed gain is closer
>>> to 5 times faster on average.
>>
>> Five times faster is certainly more attractive than twice as fast. But
>> under what
>> circumstances is this achieved? Unfortunately these days it is difficult
>> to find any solid
>> information on how things actually work, but my impression is that caches
>> only work for
>> pages which are frequently accessed. If this is correct, and (as I
>> suspect) somebody looks
>> at my website once an hour, the page will not be in the cache, so it won't
>> help. Also one
>> of the more popular parts of this website is my photo album, and for this
>> much of the
>> access time will be the download time of the photos. Furthermore as each
>> visitor will look
>> at a different set of photos, even with heavy access it is unlikely that
>> any given photo
>> would be in a cache.
>
> A particular cache of bytecode is usually pushed out of memory when the
> configured maximum amount of memory for the bytecode cache is about to be
> exceeded. Additionally, the particular cache that gets eliminated is usually
> the oldest or least used cache. Given this, and your purported usage
> patterns, your pages will most likely remain in the cache until such time as
> you update the code or restart the webserver.
>
>> Despite these comments the access times for my websites seem to be pretty
>> good --
>> certainly a lot better than many commercial websites -- but have a look at
>> http://www.corybas.com/, and see what you think

Re: [PHP] Re: PHP programming strategy; lots of little include files, or a few big ones?

2010-01-08 Thread J Ravi Menon
Sorry forgot to mention that we used APC with apc.stat turned off
which will give a little bit more performance gain, but it does mean
flushing the cache on every code push (which is trivial).

Ravi


On Fri, Jan 8, 2010 at 11:30 AM, J Ravi Menon  wrote:
> Hi,
>
> A note on bytecode caching and include/include_once performance. A
> while ago when we were profiling our code, we did notice that file
> includes do take a noticeable percentage of overall overhead (enough
> for us to look into it more deep). We are using apc cache on a
> standard LAMP platform (linux 2.6 series, apache 2.2x and PHP 5
> series).
>
> Our includes were using 'relative' paths (e.g.  include_once
> '../common/somefile.inc' or include_once 'lib/somefuncs.inc' ) and
> within APC cache logic, it resolves such relative paths to absolute
> paths via a realpath() calls. This can be fairly file-system intensive
> (lots of syscalls like stat() and readlink() to resolve symlinks
> etc...). APC uses absolute paths as key into the opcode cache.
>
> This gets worse if it has to find your files via the 'ini_path'
> setting (and most of your library or common code is not in the first
> component or so ).
>
> So from APC cache perspective, it is most efficient if your include
> paths are all absolute (realpath() logic is skipped) - e.g.:
>
> include_once $BASE_DIR . '/common/somefile.inc';
> include_once $BASE_DIR . '/lib/somefuncs.inc';
>
> and so on where '$BASE_DIR' could be set via apache Setenv directives
> ( $_SERVER['BASE_DIR'] or even hardcoded all over the place).
>
> There were other issues with include vs include_once and apc cache,
> but I don't recall why there were performance difference (with include
> only even with relative paths, the performance was better, but
> managing dependencies is to cumbersome).
>
> Not sure how other bytecode cache handles relative paths but I suspect
> it has to do something similar.
>
> From a pure code readability point of view and more automated
> dependency management (as close to compiled languages as possible), I
> do favor include_once/require_once strategy with absolute path
> strategy, but it is not unheard of where to squeeze out maximal
> performance, a giant single 'include' is done. Sometimes this is done
> on prod. systems where a parser goes through and generates this big
> include file, and ensure it is placed somewhere in the beginning the
> main 'controller.php' (MVC model) and all other includes stripped off.
>
> Hope this helps in making your decision.
>
> Ravi
>
>
> On Fri, Jan 8, 2010 at 8:59 AM, Robert Cummings  wrote:
>> clanc...@cybec.com.au wrote:
>>>
>>> On Thu, 07 Jan 2010 22:48:59 -0500, rob...@interjinn.com (Robert Cummings)
>>> wrote:
>>>
>>>> clanc...@cybec.com.au wrote:
>>>>>
>>>>> Thank you all for your comments. I did not know about bytecode caches.
>>>>> They're an
>>>>> interesting concept, but if I am interpreting the paper
>>>>> http://itst.net/654-php-on-fire-three-opcode-caches-compared correctly
>>>>> they only double
>>>>> the average speed of operation, which is rather less than I would have
>>>>> anticipated.
>>>>
>>>> I strongly advise that you take the time to try a bytecode cache. Within
>>>> linux environments I am partial to eaccelerator. In IIS environments I now
>>>> use WinCache from Microsoft. From my own observations with a multitude of
>>>> different types of PHP web applications I find that the speed gain is 
>>>> closer
>>>> to 5 times faster on average.
>>>
>>> Five times faster is certainly more attractive than twice as fast. But
>>> under what
>>> circumstances is this achieved? Unfortunately these days it is difficult
>>> to find any solid
>>> information on how things actually work, but my impression is that caches
>>> only work for
>>> pages which are frequently accessed. If this is correct, and (as I
>>> suspect) somebody looks
>>> at my website once an hour, the page will not be in the cache, so it won't
>>> help. Also one
>>> of the more popular parts of this website is my photo album, and for this
>>> much of the
>>> access time will be the download time of the photos. Furthermore as each
>>> visitor will look
>>> at a different set of photos, even with heavy access it is unlikely that
>>> any given photo
>>> would be in a cache.
>>
>> A parti

Re: [PHP] Object Oriented Programming question

2010-01-20 Thread J Ravi Menon
Hi Bob,

[Couldn't resist jumping into this topic :)]

Even if you look at traditional unix (or similar) kernel internals,
although they tend to use functional paradigms, they do have a
OOP-like flavor. Example:

Everything in a unix system is a 'file' (well not really with
networking logic, but it is one of the most important abstractions).
There is a notion of a 'abstract' base class 'file', and then there
are different 'types' of files - regular, directory, devices etc... So
you 'instantiate' a specific 'concrete' object when dealing with a
specific file. What are the methods that apply to all files? There is
open(), close(), read(), write(), ioctl() etc...  Not all methods are
valid for certain kinds of files - e.g. usually you don't write() to a
keyboard device.

In unix and C, the OOP is modeled using structs (to store various
attributes, or data members), and each struct tends to have
'pointer-to-functions' (listed above in case of files) to actual
implementation on how to deal with such objects in the system.

In fact the device-driver framework in unix can be thought of as an
excellent example of polymorphism where a table stores all the
specific functions that operate on the device.

Grouping data and its associated operations is one of the hallmarks of
OOP. In C, there is no *direct* support to express such groupings
where as in C++ (and other OOP languages), there is direct support via
notion of 'classes'  to express such relationships.

I would recommend this book: 'The design and evolution of C++' by
Bjarne Stroustrup where such topics are discussed more in depth.

Hope this helps.

Ravi




On Wed, Jan 20, 2010 at 8:31 AM, Bob McConnell  wrote:
> From: tedd
>
>> At 10:26 AM -0500 1/19/10, Bob McConnell wrote:
>>> Some problems will fit into it, some don't.
>>
>> I teach OOP thinking at the local college and haven't run into a
>> problem that doesn't fit. For example, in my last class I had a woman
>> who wanted to pick out a blue dress for her upcoming wedding
>> anniversary. The class worked out the problem with a OOP solution.
>
> Hi Tedd,
>
> Here's one you can think about. I have a box, purchased off the shelf,
> with multiple serial ports and an Ethernet port. It contains a 68EN383
> CPU with expandable flash and RAM. The firmware includes a simple driver
> application to create extended serial ports for MS-Windows, but allows
> it to be replaced with a custom application. The included SDK consists
> of the gcc cross-compiler and libraries with a Xinu kernel and default
> drivers for a variety of standard protocols.
>
> I need to build a communications node replacing the default drivers with
> custom handlers for a variety of devices. It must connect to a server
> which will send it configuration messages telling it what hardware and
> protocols will be connected to each port. The Xinu package includes
> Posix threads.
>
> In the past 23 years I have solved this problem six times with five
> different pieces of hardware. But I still don't see how to apply OOP to
> it.
>
>> 
>>
>>> Some people can look at problems and see objects and some can't.
>>
>> That's for certain -- but in time just about everyone can understand
>> the basic concepts of OOP.
>
> Understanding basic concepts and understanding how to map them on to
> real problems are two entirely different skill sets. I understand the
> concepts, they just don't make any sense to me. All of the definitions
> are backwards from the way I learned to evaluate problems. I feel like a
> carpenter trying to figure out how to use a plumber's toolbox. There are
> some things in there I think I recognize, but most of it is entirely
> foreign to me.
>
> Cheers,
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] memory efficient hash table extension? like lchash ...

2010-01-25 Thread J Ravi Menon
PHP does expose sys V shared-memory apis (shm_* functions):

http://us2.php.net/manual/en/book.sem.php

If you already have apc installed, you could also try:

http://us2.php.net/manual/en/book.apc.php

APC also allows you to store user specific data too (it will be in a
shared memory).

Haven't tried these myself, so I would do some quick tests to ensure
if they meet your performance requirements. In theory, it should be
faster than berkeley-db like solutions (which is also another option
but it seems something similar like MongoDB was not good enough?).

I  am curious to know if someone here has run these tests. Note that
with memcached installed locally (on the same box running php), it can
be surprisingly efficient - using pconnect(),  caching the handler in
a static var for a given request cycle etc...

Ravi






On Sun, Jan 24, 2010 at 9:39 AM, D. Dante Lorenso  wrote:
> shiplu wrote:
>>
>> On Sun, Jan 24, 2010 at 3:11 AM, D. Dante Lorenso 
>> wrote:
>>>
>>> All,
>>>
>>> I'm loading millions of records into a backend PHP cli script that I
>>> need to build a hash index from to optimize key lookups for data that
>>> I'm importing into a MySQL database.  The problem is that storing this
>>> data in a PHP array is not very memory efficient and my millions of
>>> records are consuming about 4-6 GB of ram.
>>>
>>
>> What are you storing? An array of row objects??
>> In that case storing only the row id is will reduce the memory.
>
> I am querying a MySQL database which contains 40 million records and mapping
> string columns to numeric ids.  You might consider it normalizing the data.
>
> Then, I am importing a new 40 million records and comparing the new values
> to the old values.  Where the value matches, I update records, but where
> they do not match, I insert new records, and finally I go back and delete
> old records.  So, the net result is that I have a database with 40 million
> records that I need to "sync" on a daily basis.
>
>> If you are loading full row objects, it will take a lot of memory.
>> But if you just load the row id values, it will significantly decrease
>> the memory amount.
>
> For what I am trying to do, I just need to map a string value (32 bytes) to
> a bigint value (8 bytes) in a fast-lookup hash.
>
>> Besides, You can load row ids in a chunk by chunk basis. if you have
>> 10 millions of rows to process. load 1 rows as a chunk. process
>> them then load the next chunk.  This will significantly reduce memory
>> usage.
>
> When importing the fresh 40 million records, I need to compare each record
> with 4 different indexes that will map the record to existing other records,
> or into a "group_id" that the record also belongs to.  My current solution
> uses a trigger in MySQL that will do the lookups inside MySQL, but this is
> extremely slow.  Pre-loading the mysql indexes into PHP ram and processing
> that was is thousands of times faster.
>
> I just need an efficient way to hold my hash tables in PHP ram.  PHP arrays
> are very fast, but like my original post says, they consume way too much
> ram.
>
>> A good algorithm can solve your problem anytime. ;-)
>
> It takes about 5-10 minutes to build my hash indexes in PHP ram currently
> which makes up for the 10,000 x speedup on key lookups that I get later on.
>  I just want to not use the whole 6 GB of ram to do this.   I need an
> efficient hashing API that supports something like:
>
>        $value = (int) fasthash_get((string) $key);
>        $exists = (bool) fasthash_exists((string) $key);
>        fasthash_set((string) $key, (int) $value);
>
> Or ... it feels like a "memcached" api but where the data is stored locally
> instead of accessed via a network.  So this is how my search led me to what
> appears to be a dead "lchash" extension.
>
> -- Dante
>
> --
> D. Dante Lorenso
> da...@lorenso.com
> 972-333-4139
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] memory efficient hash table extension? like lchash ...

2010-01-25 Thread J Ravi Menon
> values were stored, the APC storage began to slow down *dramatically*.  I
> wasn't certain if APC was using only RAM or was possibly also writing to
> disk.  Performance tanked so quickly that I set it aside as an option and
> moved on.
IIRC, i think it is built over shm and there is no disk backing store.


> memcached gives no guarantee about data persistence.  I need to have a hash
> table that will contain all the values I set.  They don't need to survive a
> server shutdown (don't need to be written to disk), but I can not afford for
> the server to throw away values that don't fit into memory.  If there is a
> way to configure memcached guarantee storage, that might work.

True but the lru policy only kicks in lazily. So if you ensure that
you never hit near the max allowed limit (-m option), and you store
your key-val pairs with no expiry, it will be present till the next
restart. So essentially you would have to estimate the value for the
-m option to big enough to accommodate all possible key-val pairs (the
evictions counter in memcached stats should remain 0). BTW, I have
seen this implementation behavior in 1.2.x series but not sure it is
necessarily guaranteed in future versions.

Ravi



On Mon, Jan 25, 2010 at 3:49 PM, D. Dante Lorenso  wrote:
> J Ravi Menon wrote:
>>
>> PHP does expose sys V shared-memory apis (shm_* functions):
>> http://us2.php.net/manual/en/book.sem.php
>
>
> I will look into this.  I really need a key/value map, though and would
> rather not have to write my own on top of SHM.
>
>
>> If you already have apc installed, you could also try:
>> http://us2.php.net/manual/en/book.apc.php
>> APC also allows you to store user specific data too (it will be in a
>> shared memory).
>
>
> I've looked into the apc_store and apc_fetch routines:
> http://php.net/manual/en/function.apc-store.php
> http://www.php.net/manual/en/function.apc-fetch.php
> ... but quickly ran out of memory for APC and though I figured out how to
> configure it to use more (adjust shared memory allotment), there were other
> problems.  I ran into issues with logs complaining about "cache slamming"
> and other known bugs with APC version 3.1.3p1.  Also, after several million
> values were stored, the APC storage began to slow down *dramatically*.  I
> wasn't certain if APC was using only RAM or was possibly also writing to
> disk.  Performance tanked so quickly that I set it aside as an option and
> moved on.
>
>
>> Haven't tried these myself, so I would do some quick tests to ensure
>> if they meet your performance requirements. In theory, it should be
>> faster than berkeley-db like solutions (which is also another option
>> but it seems something similar like MongoDB was not good enough?).
>
>
> I will run more tests against MongoDB.  Initially I tried to use it to store
> everything.  If I only store my indexes, it might fare better. Certainly,
> though, running queries and updates against a remote server will always be
> slower than doing the lookups locally in ram.
>
>
>> I  am curious to know if someone here has run these tests. Note that
>> with memcached installed locally (on the same box running php), it can
>> be surprisingly efficient - using pconnect(),  caching the handler in
>> a static var for a given request cycle etc...
>
> memcached gives no guarantee about data persistence.  I need to have a hash
> table that will contain all the values I set.  They don't need to survive a
> server shutdown (don't need to be written to disk), but I can not afford for
> the server to throw away values that don't fit into memory.  If there is a
> way to configure memcached guarantee storage, that might work.
>
> -- Dante
>
>
>> On Sun, Jan 24, 2010 at 9:39 AM, D. Dante Lorenso 
>> wrote:
>>>
>>> shiplu wrote:
>>>>
>>>> On Sun, Jan 24, 2010 at 3:11 AM, D. Dante Lorenso 
>>>> wrote:
>>>>>
>>>>> All,
>>>>>
>>>>> I'm loading millions of records into a backend PHP cli script that I
>>>>> need to build a hash index from to optimize key lookups for data that
>>>>> I'm importing into a MySQL database.  The problem is that storing this
>>>>> data in a PHP array is not very memory efficient and my millions of
>>>>> records are consuming about 4-6 GB of ram.
>>>>>
>>>> What are you storing? An array of row objects??
>>>> In that case storing only the row id is will reduce the memory.
>>>
>>> I am querying a MySQL database which contains 40 million records and
>>> mappin

Re: [PHP] Re: Best Practices Book, Document, Web Site?

2010-03-05 Thread J Ravi Menon
Other than coding standards, the other good read is:
(it seems to cover most topics I have ran into while maintaining a
high traffic site implemented in php 5):

http://phplens.com/lens/php-book/optimizing-debugging-php.php

It is 'best practices' from another angle - use of opcode cache (apc
etc..), output buffering and so on.

Coding standards vary a lot, so I would recommend sticking to one
style once a consensus is reached among the team and preferably
enforce it in automated fashion (e.g.
http://pear.php.net/package/PHP_CodeSniffer/ as a svn pre-commit
hook).

The other easily over-looked part I have seen in many php projects is
the code layout and directory structure, including dependency
management (library code vs business logic etc..), and more
importantly only exposing the main 'entry point' scripts (index.php or
controller.php in a MVC model) in a apache doc root. Many times I have
seen poorly laid out code that ends up getting deployed with the
entire code bases exposed in a apache doc root. If care is not taken
(e.g. naming some files .inc and no special apache rules to interpret
them as a php handler), it is a security nightmare with critical files
getting exposed.

I have my own layout suggestion which has worked well for us, and once
mastered, it makes everyone in the team very productive. Maybe this
can be a separate topic in its own right.

Ravi





On Tue, Mar 2, 2010 at 9:51 AM, Hansen, Mike  wrote:
>
>
>> -Original Message-
>> From: Bob McConnell [mailto:r...@cbord.com]
>> Sent: Tuesday, March 02, 2010 7:52 AM
>> To: pan; php-general@lists.php.net
>> Subject: RE: [PHP] Re: Best Practices Book, Document, Web Site?
>>
>> From: pan
>> > ""Hansen, Mike""  wrote in message
>> >>
>> news:7941b2693f32294aaf16c26b679a258d0efdc...@csomb01.corp.atm
>> el.com...
>> >> Is there a PHP Best Practices Book, Document, or web site that has
>> >> information similar to Perl Best Practices but for PHP?
>> >
>> > Yeah, it's hard to find this stuff.
>> >
>> > A google search on {+"Best Practices" +"PHP"} returned only
>> > 4,340,000 hits.
>> >
>> > Maybe, some day, someone will think to write something up.
>>
>> The problem with this method is that scanning these results reveals
>> conflicting and contradictory recommendations that are all over the
>> place. Some are so old they may not even be valid PHP any
>> more. Reading
>> even a small subset of these pages is an exercise in frustration. But
>> that makes sense as there doesn't appear to be any consistency nor
>> consensus within the community, or even within some of the larger
>> projects.
>>
>> Speaking of consensus, based on a recent discussion on the Perl
>> Beginners mailing list, the Perl Best Practices book is now considered
>> to be deprecated among the active Perl community. Many of its
>> recommendations are obsolete and no longer used. It is long
>> past due for
>> a major rewrite.
>>
>> Bob McConnell
>
> Yep. Perl Best Practices is due for a rewrite/update. I came across this page 
> that attempts to update it:
> http://www.perlfoundation.org/perl5/index.cgi?pbp_module_recommendation_commentary
>
> For PHP, I'll stick with the PEAR recommendations and do the best I can with 
> whatever is missing.
>
> Thanks.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



[PHP] php cli question

2010-09-10 Thread J Ravi Menon
Hi,

I have some basic questions on running php  (5.2.x series on Linux
2.6) as a standalone daemon using posix methods (fork() etc..):

#!/usr/bin/php
doSomething()

}

// shutdown logic.

The 'someclass.php' in turn will include other files (via require_once).

The above file will be executed directly from the shell. The main loop
could be listening to new requests via sockets etc..

Few questions:

1) Does opcode cache really matter in such cli-based daemons? As
'SomeClass' is instantiated at every loop, I am assuming it is only
compiled once as it has already been 'seen'.
I am not very clear on how apc (or eaccelerator) works in such cases.


2) What about garbage collection? In a standard apache-mod-php setup,
we rely on the end of a request-cycle to free up resources - close
file descriptiors, free up memory etc..
I am assuming in the aforesaid standalone daemon case, we would
have to do this manually?  In the loop above, would it be better to
'unset($a)' explicitly at the end of it before
it goes to the next iteration?

Note: I have written pre-forker deamons in php directly and
successfully deployed them in the past, but never looked at in depth
to understand all the nuances. Anecdotally, I have
done 'unset()' at some critical places were large arrays were used,
and I think it helped. AFAIK, unlike Java, there is no 'garbage
collector' thread that does all the magic?

Thanks,
Ravi

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



[PHP] Re: php cli question

2010-09-13 Thread J Ravi Menon
On Sat, Sep 11, 2010 at 8:50 PM, Shawn McKenzie  wrote:
> On 09/10/2010 11:13 AM, J Ravi Menon wrote:
>> Hi,
>>
>> I have some basic questions on running php  (5.2.x series on Linux
>> 2.6) as a standalone daemon using posix methods (fork() etc..):
>>
>> #!/usr/bin/php
>> >
>> require_once ('someclass.php');
>>
>> // do some initializations
>> .
>>
>> // main 'forever' loop - the '$shutdown'  will
>> // be set to true via a signal handler
>>
>> while(!$shutdown)
>> {
>>   $a = new SomeClass();
>>
>>   $a->doSomething()
>>
>> }
>>
>> // shutdown logic.
>>
>> The 'someclass.php' in turn will include other files (via require_once).
>>
>> The above file will be executed directly from the shell. The main loop
>> could be listening to new requests via sockets etc..
>>
>> Few questions:
>>
>> 1) Does opcode cache really matter in such cli-based daemons? As
>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>> compiled once as it has already been 'seen'.
>>     I am not very clear on how apc (or eaccelerator) works in such cases.
>>
>>
>> 2) What about garbage collection? In a standard apache-mod-php setup,
>> we rely on the end of a request-cycle to free up resources - close
>> file descriptiors, free up memory etc..
>>     I am assuming in the aforesaid standalone daemon case, we would
>> have to do this manually?  In the loop above, would it be better to
>> 'unset($a)' explicitly at the end of it before
>>     it goes to the next iteration?
>>
>> Note: I have written pre-forker deamons in php directly and
>> successfully deployed them in the past, but never looked at in depth
>> to understand all the nuances. Anecdotally, I have
>> done 'unset()' at some critical places were large arrays were used,
>> and I think it helped. AFAIK, unlike Java, there is no 'garbage
>> collector' thread that does all the magic?
>>
>> Thanks,
>> Ravi
>
> If I have time when you reply I'll answer the questions, but I must ask:
>  Is this purely academic?  Why is this a concern?  Have you encountered
> issues?  If so, what?

@Tom: I have compiled php with pcntl on and this has never been an
issue. It works well (on a linux setup), and I have deployed
standalone daemons with out any major problems. I have a home-grown
'preforker' framework (which I hope to share soon) which can be used
to exploit multi-core boxes.

@Shawn: It is not academic. There is a follow-up I am planning based
on the doubts above. I have deployed such daemons in the past with
some assumptions on (2) by doing manual cleanups - e.g. closing curl
connections, closing up db handles etc...  Really want to understand
how php works in such setups outside of apache+mod_php.

thanks,
Ravi







>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>

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



Re: [PHP] php cli question

2010-09-14 Thread J Ravi Menon
On Tue, Sep 14, 2010 at 12:43 AM, Per Jessen  wrote:
> J Ravi Menon wrote:
>
>> Few questions:
>>
>> 1) Does opcode cache really matter in such cli-based daemons? As
>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>> compiled once as it has already been 'seen'.
>
> Yup.

Just to clarify, you mean we don't need the op-code cache here right?


>
>> 2) What about garbage collection? In a standard apache-mod-php setup,
>> we rely on the end of a request-cycle to free up resources - close
>> file descriptiors, free up memory etc..
>>     I am assuming in the aforesaid standalone daemon case, we would
>> have to do this manually?
>
> Yes.
>

So 'unset($some_big_array)'  or 'unset($some_big_object)' etc.. is the
right way to go for non-resource based items? i.e. it needs to be
explicitly done?

thx,
Ravi



>> Note: I have written pre-forker deamons in php directly and
>> successfully deployed them in the past, but never looked at in depth
>> to understand all the nuances. Anecdotally, I have
>> done 'unset()' at some critical places were large arrays were used,
>> and I think it helped. AFAIK, unlike Java, there is no 'garbage
>> collector' thread that does all the magic?
>
> Correct.
>
>
>
> --
> Per Jessen, Zürich (12.9°C)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] php cli question

2010-09-14 Thread J Ravi Menon
On Tue, Sep 14, 2010 at 1:15 PM, Per Jessen  wrote:
> J Ravi Menon wrote:
>
>> On Tue, Sep 14, 2010 at 12:43 AM, Per Jessen  wrote:
>>> J Ravi Menon wrote:
>>>
>>>> Few questions:
>>>>
>>>> 1) Does opcode cache really matter in such cli-based daemons? As
>>>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>>>> compiled once as it has already been 'seen'.
>>>
>>> Yup.
>>
>> Just to clarify, you mean we don't need the op-code cache here right?
>
> That is correct.
>
>>>> 2) What about garbage collection? In a standard apache-mod-php
>>>> setup, we rely on the end of a request-cycle to free up resources -
>>>> close file descriptiors, free up memory etc..
>>>> I am assuming in the aforesaid standalone daemon case, we would
>>>> have to do this manually?
>>>
>>> Yes.
>>
>> So 'unset($some_big_array)'  or 'unset($some_big_object)' etc.. is the
>> right way to go for non-resource based items? i.e. it needs to be
>> explicitly done?
>
> It's not quite like C - if you reassign something, the previous contents
> are automagically freed.  I use unset() if I know it could be a while
> (hours) before it'll likely be reassigned, but it won't be used in the
> meantime.
>

Thanks Per for clarifying this for me. Now on my follow up question:

[Note: I think it is related to the issues discussed above hence
keeping it on this thread but if I am violating any guidelines here,
do let me know]

One reason the aforesaid questions got triggered was that in our
company right now, there is a big discussion on moving away from
apache+mod_php solution to nginx+fast-cgi based model for handling all
php-based services. The move seems to be more based some anecdotal
observations and possibly not based on a typical php-based app (i.e.
the php script involved was trivial one acting as some proxy to
another backend service).

I have written fast-cgi servers in the past in C++, and I am aware how
the apahce<>fast-cgi-servers work (in unix socket setups).  All
our php apps are written with apache+mod_php in mind (no explicit
resource mgmt ), so this was a concern to me.

If the same scripts now need to run 'forever' as a fastcgi server, are
we forced to do such manual resource mgmt? Or are there solutions here
that work just as in mod_php?

This reminded me of the cli daemons that I had written earlier where
such manual cleanups were done, and hence my doubts on this
nginx+fast-cgi approach.

thx,
Ravi


>
>
> --
> Per Jessen, Zürich (14.6°C)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] php cli question

2010-09-15 Thread J Ravi Menon
Thanks Bostjan for the suggestion. I did raise the issue and here is the reply:

http://news.php.net/php.internals/49672

Thx,
Ravi


On Wed, Sep 15, 2010 at 2:38 AM, Bostjan Skufca  wrote:
> Here are the results I got when question of migration from apache to nginx
> was brought up:
> http://blog.a2o.si/2009/06/24/apache-mod_php-compared-to-nginx-php-fpm/
> (BTW there is some FPM in main PHP distribution now)
>
> As for resource management, I recommend looking at php sources
> (Zend/zend_alloca.c:zend_mm_shutdown() specifically) and building a custom
> extension that frees discarded memory resources on your request or timer or
> sth else. Not sure if it is possible like that but this is just a
> suggestion, don't quote me on that :)
> Also, for such questions I recommend you to join php-internals mailing list,
> it seems more appropriate.
>
> b.
>
>
> On 15 September 2010 04:19, J Ravi Menon  wrote:
>>
>> On Tue, Sep 14, 2010 at 1:15 PM, Per Jessen  wrote:
>> > J Ravi Menon wrote:
>> >
>> >> On Tue, Sep 14, 2010 at 12:43 AM, Per Jessen  wrote:
>> >>> J Ravi Menon wrote:
>> >>>
>> >>>> Few questions:
>> >>>>
>> >>>> 1) Does opcode cache really matter in such cli-based daemons? As
>> >>>> 'SomeClass' is instantiated at every loop, I am assuming it is only
>> >>>> compiled once as it has already been 'seen'.
>> >>>
>> >>> Yup.
>> >>
>> >> Just to clarify, you mean we don't need the op-code cache here right?
>> >
>> > That is correct.
>> >
>> >>>> 2) What about garbage collection? In a standard apache-mod-php
>> >>>> setup, we rely on the end of a request-cycle to free up resources -
>> >>>> close file descriptiors, free up memory etc..
>> >>>> I am assuming in the aforesaid standalone daemon case, we would
>> >>>> have to do this manually?
>> >>>
>> >>> Yes.
>> >>
>> >> So 'unset($some_big_array)'  or 'unset($some_big_object)' etc.. is the
>> >> right way to go for non-resource based items? i.e. it needs to be
>> >> explicitly done?
>> >
>> > It's not quite like C - if you reassign something, the previous contents
>> > are automagically freed.  I use unset() if I know it could be a while
>> > (hours) before it'll likely be reassigned, but it won't be used in the
>> > meantime.
>> >
>>
>> Thanks Per for clarifying this for me. Now on my follow up question:
>>
>> [Note: I think it is related to the issues discussed above hence
>> keeping it on this thread but if I am violating any guidelines here,
>> do let me know]
>>
>> One reason the aforesaid questions got triggered was that in our
>> company right now, there is a big discussion on moving away from
>> apache+mod_php solution to nginx+fast-cgi based model for handling all
>> php-based services. The move seems to be more based some anecdotal
>> observations and possibly not based on a typical php-based app (i.e.
>> the php script involved was trivial one acting as some proxy to
>> another backend service).
>>
>> I have written fast-cgi servers in the past in C++, and I am aware how
>> the apahce<>fast-cgi-servers work (in unix socket setups).  All
>> our php apps are written with apache+mod_php in mind (no explicit
>> resource mgmt ), so this was a concern to me.
>>
>> If the same scripts now need to run 'forever' as a fastcgi server, are
>> we forced to do such manual resource mgmt? Or are there solutions here
>> that work just as in mod_php?
>>
>> This reminded me of the cli daemons that I had written earlier where
>> such manual cleanups were done, and hence my doubts on this
>> nginx+fast-cgi approach.
>>
>> thx,
>> Ravi
>>
>>
>> >
>> >
>> > --
>> > Per Jessen, Zürich (14.6°C)
>> >
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>

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



Re: [PHP] PHP Email Question

2010-09-21 Thread J Ravi Menon
Just on this topic, I found swiftmailer library to be really useful
esp. in dealing with 'template' emails with custom variables per
recipient:

http://swiftmailer.org/

The e.g. on email template processing:

http://swiftmailer.org/docs/decorator-plugin-howto

There are batchSend() functionalities, ability to compose various mime
type emails etc...

Ravi

On Mon, Sep 20, 2010 at 8:20 AM, chris h  wrote:
>> Ignore the other parameters unless you are very familiar with RFCs 2821,
>> 2822 and their associated RFCs
>>
>
>
> I would advise against ignoring the other parameters.  Doing so will pretty
> much guarantee having your email end up in SPAM.  Instead look up the
> examples in the docs, or better yet use something like phpmailer as Tom
> suggested.
>
>
> Chris.
>
>
> On Sun, Sep 19, 2010 at 6:37 PM, TR Shaw  wrote:
>
>>
>> On Sep 19, 2010, at 6:00 PM, Joe Jackson wrote:
>>
>> > Hi
>> >
>> > Sorry for the simple question but I am trying to get my head around PHP.
>>  I
>> > have a sample PHP script that I am trying to use to send a php powered
>> email
>> > message.  The snippet of code is shown below
>> >
>> >    mail('em...@address.com', 'Subject', $values['message'], "From:
>> > \"{$values['name']}\" <{$values['emailaddress']}>");
>> >
>> > This works fine, but how can I add in other fields to the email that is
>> > recieved?
>> >
>> > For example in the form there are fields called, 'emailaddress',
>> > 'telephone', 'address' and 'name' which I need to add into the form along
>> > with the message field
>> >
>> > Also with the formatting how can I change the format of the email to
>> >
>> > Name: $values['name'],
>> > Address: etc
>> > Message:
>> >
>>
>> Joe
>>
>> The mail command lets you send mail (an RFC2821 envelop). The function is:
>>
>> bool mail ( string $to , string $subject , string $message [, string
>> $additional_headers [, string$additional_parameters ]] )
>>
>> $to is where you want it to go
>> $subject is whatever you want the subject to be
>> $message is the information you want to send
>
> Ignore the other parameters unless you are very familiar with RFCs 2821,
>> 2822 and their associated RFCs
>
>
>> So if you want to send info from a form you might want to roll it up in xml
>> and send it via the message part. when you receive it you can easily decode
>> it. If you don't want to do that put it in a format that you can easily
>> decode on the receiving end.
>>
>> Basically "mail" is a way to deliver information in the $message body. How
>> you format the information there is up to you. However, depending on your
>> system's config you are probably constrained to placing only 7bit ascii in
>> the $message body.
>>
>> You might also move away from the mail function and look at phpmailer at
>> sf.net if you need more complex capabilities.
>>
>> Tom
>>
>>
>>
>>
>

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



Re: [PHP] PHP Email Question

2010-09-30 Thread J Ravi Menon
On Wed, Sep 29, 2010 at 1:37 PM, Joe Jackson  wrote:
> Hi
>
> I am trying the following snippet as Bostjan  suggested, and an email is
> getting sent when I submit the form however in the body of the email I am
> getting none of the form data in the body of the email.  All I am getting is
> the letter 'z' ?  Also in the from field of the email this is showing as my
> email address and not the email address of the user who has sent the form
>
> Any ideas on where I am going wrong with this snippet?  Any advice would be
> much appreciated
>
> $msgContent = "Name: ". $values['name'] ."\n";
> $msgContent .= "Address: ". $values['address'] ."\n";
> $msgContent .= "Telephone: ". $values['telephone'] ."\n";
> $msgContent .= "Email Address: ". $values['emailaddress'] ."\n";
> $msgContent .= "Message: ". $values['message'] ."\n";
>
> function ProcessForm($values)
> {
>     mail('myemail:domain.com', 'Website Enquiry', $msgContent, "From:
> \"{$values['name']}\" <{$values['emailaddress']}>");
>
>  // Replace with actual page or redirect :P
>     echo "Thank you!Thank
> you!";

Not sure if it it is a typo above, are you actually passing
$msgContent in the function above? If it is a global variable, you
would need to add a 'global' declaration:

function ProcessForm($values)
{
   global $msgContent;

mail('myemail:domain.com', 'Website Enquiry', $msgContent, "From:
\"{$values['name']}\" <{$values['emailaddress']}>\r\n");
.
.
.
}

Also try adding CRLF sequence at the end of the header line as shown above.

Ravi

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



Re: [PHP] Model View Concepts

2010-10-25 Thread J Ravi Menon
On Fri, Oct 22, 2010 at 3:03 AM, Ashley Sheridan
 wrote:
> On Fri, 2010-10-22 at 10:16 +0200, Sebastian Detert wrote:
>
>> Hi all,
>>
>> I'm currently searching for any code snippets, tutorials, howtos,
>> concepts which explain different ways to collect all type of data/input
>> (i.e. inside a class, xml, json string whatever) and create independent
>> html files (i.e. different designs), xml files, pdf files, etc. out of
>> that pool of data. Do you have any urls or own experience you could share?
>>
>> Thanks,
>> Sebastian
>>
>
>
> How about looking into using a framework like CodeIgniter? I know I plug
> it a little bit on this list, but of all the frameworks I've used, I've
> found it the easiest to get running from scratch, and can be the
> quickest to get working for someone new to frameworks.
>
> Basically, it handles the way bothersome stuff with pulling in various
> models etc for a controller, and lets you get on with actually building
> the code that makes the website work.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
One MVC framework I have used recently is Kohana:

http://docs.kohanaphp.com/

See links on models, views etc.. It has a OOP flavor, and considered
fairly lightweight. I have written my own simplistic MVC framework
which is more efficient but definitely not as feature rich as Kohana.
There are good hooks for db handling (which will do input validation,
escaping etc..).

Ravi

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



Re: [PHP] Application settings, configuration, and preferences.

2010-10-27 Thread J Ravi Menon
I am partial to the filesystem but I can see scenarios where the db
approach might be useful (single point of control) with good caching
strategy using apc or other mechanisms.

One approach I have followed is that if the config. field and values
are simple key-value pairs, you could store them in a dedicated conf
file and have it included in the main apache conf file (Include
directive). This way, all the configs are accessible via $_SERVER. The
separate conf file can be checked in svn, pushed separately as part of
release process etc...  The same approach also works in standalone php
cli scripts via a shell wrapper - e.g.:

#!/bin/bash
.
# list fields directly here or load them separately - e.g:
#  . /path/to/some_file.conf
export FIELD1="foo"
export FIELD2 ="bar"

# Note: values can have some structure too
export FIELD3="abc,cde,fgh"
.
.
/usr/bin/php some_script.php

You could also use the php ini style confs:

http://php.net/manual/en/function.parse-ini-file.php

In the $_SERVER approach above, the parsing is done at start-up, so
there is no setup cost at every request. For the ini or xml parsing
approach, you may need to cache the result if this parsing cost needs
to be avoided on every request.

Ravi



On Wed, Oct 27, 2010 at 10:17 AM, Michael Shadle  wrote:
> I find json to be the most ideal data exchange format but using it for 
> configuration files one may edit by hand is horrible. XML, ini or yaml would 
> be better. I still prefer XML. Albeit verbose it is the easiest to read and 
> easy to validate against.
>
> On Oct 27, 2010, at 10:12 AM, "Bob McConnell"  wrote:
>
>> From: Ken Guest
>>
>>> On Wed, Oct 27, 2010 at 5:27 PM,  wrote:
>>>> Recently we had a discussion about weather our code should be
>> configured
>>>> using files or a DB back-end.  As this topic effects nearly every
>>>> development team I was wondering if there shouldn't be a common
>> library
>>>> that deals with all of these issues.
>>>>
>>>> We came to the conclusion that either should work, but our project
>> must
>>>> work on systems that would not have an SQLDB installed.  There fore
>> it
>>>> must be configured using files as supporting both would be a waste of
>>>> our development time.
>>>>
>>>> Looking around for a solution I came across an extension to getopt
>> that
>>>> read command line parameters from a file, essentially emulating "exec
>>>> $(cat);".  As this did allow configuration from either the command
>> line
>>>> or a file it's a good start.  However we are specificually looking
>> for
>>>> something that would accept configuration from a file or a DB,
>> command
>>>> line options are not important.  Though a great solution would take
>>>> configuration from anywhere.
>>>>
>>>> A full featured solution would also support containing user
>> preferences
>>>> and administrative settings.  Allowing any of these to come from
>> almost
>>>> anywhere.  Here is how an example deployment might work.  As this
>> would
>>>> be a programming tool the user would be an administrator installing
>> and
>>>> configuring the software.
>>>>
>>>> Some configuration information contained in php should be extensible
>> so
>>>> that all the configuration could be done there.  In this case
>> settings
>>>> and user preferences would be read-only, configuration information is
>>>> always read-only.  This would usually specify a config file to be
>>>> located in the same folder or a subfolder.
>>>>
>>>> This configuration file would have a default format that is
>> configurable
>>>> in the php.  Would be one of PHP, XML, bind, apache, and several
>> other
>>>> config file formats.  This file would contain information on where
>>>> settings and preferences could be written to, either another
>>>> configuration file some where in /var or connection information for a
>> DB.
>>>>
>>>> From an application developers stand point this should all be as
>>>> difficult as getopt to setup, design decisions like what format the
>>>> config file is in should be left up to the admin installing the
>>>> software.  The developer need only be concerned with defining the
>> values
>>>> stored, there type, and other properties.
>>>>
>>>> Does anything like this exist?  This seams like an essential piece of
>>>> code that is

Re: [PHP] Application settings, configuration, and preferences.

2010-10-27 Thread J Ravi Menon
On Wed, Oct 27, 2010 at 11:39 AM, J Ravi Menon  wrote:
> I am partial to the filesystem but I can see scenarios where the db
> approach might be useful (single point of control) with good caching
> strategy using apc or other mechanisms.
>
> One approach I have followed is that if the config. field and values
> are simple key-value pairs, you could store them in a dedicated conf
> file and have it included in the main apache conf file (Include
> directive). This way, all the configs are accessible via $_SERVER. The
> separate conf file can be checked in svn, pushed separately as part of
> release process etc...  The same approach also works in standalone php
> cli scripts via a shell wrapper - e.g.:
>
> #!/bin/bash
> .
> # list fields directly here or load them separately - e.g:
> #  . /path/to/some_file.conf
> export FIELD1="foo"
> export FIELD2 ="bar"
>
> # Note: values can have some structure too
> export FIELD3="abc,cde,fgh"
> .
> .
> /usr/bin/php some_script.php
>
> You could also use the php ini style confs:
>
> http://php.net/manual/en/function.parse-ini-file.php
>
> In the $_SERVER approach above, the parsing is done at start-up, so
> there is no setup cost at every request. For the ini or xml parsing
> approach, you may need to cache the result if this parsing cost needs
> to be avoided on every request.
>
> Ravi
>
>
>
> On Wed, Oct 27, 2010 at 10:17 AM, Michael Shadle  wrote:
>> I find json to be the most ideal data exchange format but using it for 
>> configuration files one may edit by hand is horrible. XML, ini or yaml would 
>> be better. I still prefer XML. Albeit verbose it is the easiest to read and 
>> easy to validate against.
>>
>> On Oct 27, 2010, at 10:12 AM, "Bob McConnell"  wrote:
>>
>>> From: Ken Guest
>>>
>>>> On Wed, Oct 27, 2010 at 5:27 PM,  wrote:
>>>>> Recently we had a discussion about weather our code should be
>>> configured
>>>>> using files or a DB back-end.  As this topic effects nearly every
>>>>> development team I was wondering if there shouldn't be a common
>>> library
>>>>> that deals with all of these issues.
>>>>>
>>>>> We came to the conclusion that either should work, but our project
>>> must
>>>>> work on systems that would not have an SQLDB installed.  There fore
>>> it
>>>>> must be configured using files as supporting both would be a waste of
>>>>> our development time.
>>>>>
>>>>> Looking around for a solution I came across an extension to getopt
>>> that
>>>>> read command line parameters from a file, essentially emulating "exec
>>>>> $(cat);".  As this did allow configuration from either the command
>>> line
>>>>> or a file it's a good start.  However we are specificually looking
>>> for
>>>>> something that would accept configuration from a file or a DB,
>>> command
>>>>> line options are not important.  Though a great solution would take
>>>>> configuration from anywhere.
>>>>>
>>>>> A full featured solution would also support containing user
>>> preferences
>>>>> and administrative settings.  Allowing any of these to come from
>>> almost
>>>>> anywhere.  Here is how an example deployment might work.  As this
>>> would
>>>>> be a programming tool the user would be an administrator installing
>>> and
>>>>> configuring the software.
>>>>>
>>>>> Some configuration information contained in php should be extensible
>>> so
>>>>> that all the configuration could be done there.  In this case
>>> settings
>>>>> and user preferences would be read-only, configuration information is
>>>>> always read-only.  This would usually specify a config file to be
>>>>> located in the same folder or a subfolder.
>>>>>
>>>>> This configuration file would have a default format that is
>>> configurable
>>>>> in the php.  Would be one of PHP, XML, bind, apache, and several
>>> other
>>>>> config file formats.  This file would contain information on where
>>>>> settings and preferences could be written to, either another
>>>>> configuration file some where in /var or connection information for a
>>> DB.
>>>>>
>>>>> From an applicat

[PHP] setcookie on PHP??

2003-02-12 Thread Balaravi, Bala (Ravi), ALABS
I need to set a cookie within a document in PHP? setcookie didn't work. I guess it 
works only in PHP3 & PHP4
Any good ideas??

Thanks
Rave

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