Re: [PHP] FYI: Apache/PHP exploit

2013-10-31 Thread Camilo Sperberg


On 31 okt. 2013, at 01:55, Joshua Kehn j...@kehn.us wrote:

 Summary for those on phones?
 
 Best,
 
 -Josh
 ___
 http://byjakt.com
 Currently mobile
 
 On Oct 30, 2013, at 8:37 PM, Tamara Temple tamouse.li...@gmail.com wrote:
 
 This info cruised by my screen from G+ today, thought I’d at least pass it 
 along:
 
 http://www.exploit-db.com/exploits/29290/
 
 
 
 -- 
 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
 

It opens a shell on default ubuntu/debian lamp's, compromising several versions 
of php, including the 5.5 branch. 

Sent from my iPhone 6 Beta [Confidential use only]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sending PHP mail with Authentication

2013-09-25 Thread Camilo Sperberg
Another vote for PHPMailer, I have it working several years already
(authenticating against a Zimbra and Outlook SMTP server) without problems.

Greetings.


On Wed, Sep 25, 2013 at 11:12 PM, Aziz Saleh azizsa...@gmail.com wrote:

 Usually if I am using a framework I would use the SMTP library associated
 with it. If it doesn't have one, I use phpmailer, fast and easy to setup:

 http://phpmailer.worxware.com/index.php?pg=examplebsmtp

 Aziz


 On Wed, Sep 25, 2013 at 4:11 PM, dealTek deal...@gmail.com wrote:

  Hi All,
 
  Semi newbie email question...
 
  I have used the - mail() — Send mail php function to send email from a
  site.
 
  now it seems the server is blocking this for safety because I should be
  using authentication
 
  Q: mail() does not have authentication - correct?
 
  Q: So I read from the link below that maybe I should use - PEAR Mail
  package  is this a good choice to send mail with authentication?
 
  ...any suggestions for basic sending email with authentication (setup
 info
  and links also) would be welcome
 
 
 
 
 http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
 
  --
  Thanks,
  Dave - DealTek
  deal...@gmail.com
  [db-3]
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 



Re: [PHP] Sending PHP mail with Authentication

2013-09-25 Thread Camilo Sperberg
On Wed, Sep 25, 2013 at 11:48 PM, Camilo Sperberg m...@unreal4u.com wrote:
 Another vote for PHPMailer, I have it working several years already
 (authenticating against a Zimbra and Outlook SMTP server) without problems.

 Greetings.


 On Wed, Sep 25, 2013 at 11:12 PM, Aziz Saleh azizsa...@gmail.com wrote:

 Usually if I am using a framework I would use the SMTP library associated
 with it. If it doesn't have one, I use phpmailer, fast and easy to setup:

 http://phpmailer.worxware.com/index.php?pg=examplebsmtp

 Aziz


 On Wed, Sep 25, 2013 at 4:11 PM, dealTek deal...@gmail.com wrote:

  Hi All,
 
  Semi newbie email question...
 
  I have used the - mail() — Send mail php function to send email from a
  site.
 
  now it seems the server is blocking this for safety because I should be
  using authentication
 
  Q: mail() does not have authentication - correct?
 
  Q: So I read from the link below that maybe I should use - PEAR Mail
  package  is this a good choice to send mail with authentication?
 
  ...any suggestions for basic sending email with authentication (setup
  info
  and links also) would be welcome
 
 
 
 
  http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
 
  --
  Thanks,
  Dave - DealTek
  deal...@gmail.com
  [db-3]
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 



Another vote for PHPMailer, I have it working several years already
(authenticating against a Zimbra and Outlook SMTP server) without
problems.

Greetings.

PD: Sorry for previous mail, it has been some time that I haven't used
the webmail interface of gmail :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/

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



Re: [PHP] Friday's Question

2013-09-20 Thread Camilo Sperberg

On 20 sep. 2013, at 18:51, Tedd Sperling t...@sperling.com wrote:

 Hi gang:
 
 Do you use a Mousepad?
 
 My reason for asking is that I've used a Mousepad ever since mice first came 
 out (back when they had one ball).
 
 Now that mice are optical (no balls), Mousepads are not really needed -- or 
 so I'll told by the college -- you see, they don't provide Mousepads for 
 their student's computers.
 
 As such, I wondered what's the percentage of programmers still using a 
 Mousepad?
 
 Secondly, are Mousepads used primarily by older programmers (like me) while 
 younger programmers don't use Mousepads, or what?
 
 So -- please respond with:
 
 Age: *
 Mousepad: Yes/No
 
 Thank you,
 
 tedd
 
 PS: * If you don't want to provide your actual age, then indicate your age by 
 stating young, middle-age, old-age, ancient, or whatever term 
 describes your age.
 
 Alternate -- I claim that you can tell a man's age by ten-times the number of 
 personal products he routinely uses, for example:
 
 Years Old - Personal Products
 10Toothpaste
 20Toothpaste, Deodorant
 30Toothpaste, Deodorant, Aftershave
 40Toothpaste, Deodorant, Aftershave, Minoxidil
 50Toothpaste, Deodorant, Aftershave, Minoxidil, Preparation-H
 60Toothpaste, Deodorant, Aftershave, Minoxidil, Preparation-H, Bag Bomb
 70Toothpaste, Deodorant, Aftershave, Minoxidil, Preparation-H, Bag Bomb, 
 Fixodent
 
 So, you could indicate age by stating Bag Bomb like me.
 
 ___
 tedd sperling
 t...@sperling.com
 
 
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


Age: Aftershave (but I've began using it only a year ago xD)
Mousepad: No, but if I had to use a mouse, I prefer a mousepad

I currently use only my MBP's trackpad, and it is so customizable I ended up 
buying a magic trackpad for my Mac at work as well. But, back in the days of 
Windows I was using a mousepad, mainly because it just looks better than having 
nothing at all.

Greetings.



Met vriendelijke groet,
Camilo Sperberg


W: http://unreal4u.com
T: http://twitter.com/unreal4u


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



Re: [PHP] high traffic websites

2013-09-18 Thread Camilo Sperberg

On Sep 18, 2013, at 09:38, Negin Nickparsa nickpa...@gmail.com wrote:

 Thank you Sebastian..actually I will already have one if qualified for the
 job. Yes, and I may fail to handle it that's why I asked for guidance.
 I wanted some tidbits to start over. I have searched through yslow,
 HTTtrack and others.
 I have searched through php list in my email too before asking this
 question. it is kind of beneficial for all people and not has been asked
 directly.
 
 
 Sincerely
 Negin Nickparsa
 
 
 On Wed, Sep 18, 2013 at 10:45 AM, Sebastian Krebs krebs@gmail.comwrote:
 
 
 
 
 2013/9/18 Negin Nickparsa nickpa...@gmail.com
 
 In general, what are the best ways to handle high traffic websites?
 
 VPS(clouds)?
 web analyzers?
 dedicated servers?
 distributed memory cache?
 
 
 Yes :)
 
 But seriously: That is a topic most of us spent much time to get into it.
 You can explain it with a bunch of buzzwords. Additional, how do you define
 high traffic websites? Do you already _have_ such a site? Or do you
 _want_ it? It's important, because I've seen it far too often, that
 projects spent too much effort in their high traffic infrastructure and
 at the end it wasn't that high traffic ;) I wont say, that you cannot be
 successfull, but you should start with an effort you can handle.
 
 Regards,
 Sebastian
 
 
 
 
 Sincerely
 Negin Nickparsa
 
 
 
 
 --
 github.com/KingCrunch
 

Your question is way too vague to be answered properly... My best guess would 
be that it depends severely on the type of website you have and how's the 
current implementation being well... implemented.

Simply said: what works for Facebook may/will not work for linkedIn, twitter or 
Google, mainly because the type of search differs A LOT: facebook is about 
relations between people, twitter is about small pieces of data not mainly 
interconnected between each other, while Google is all about links and all type 
of content: from little pieces of information through whole Wikipedia.

You could start by studying how varnish and redis/memcached works, you could 
study about how proxies work (nginx et al), CDNs and that kind of stuff, but if 
you want more specific answers, you could better ask specific question.

In the PHP area, an opcode cache does the job very well and can accelerate the 
page load by several orders of magnitude, I recommend OPCache, which is already 
included in PHP 5.5.

Greetings.


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



Re: [PHP] high traffic websites

2013-09-18 Thread Camilo Sperberg

On Sep 18, 2013, at 14:26, Haluk Karamete halukkaram...@gmail.com wrote:

 I recommend OPCache, which is already included in PHP 5.5.
 
 Camilo,
 I'm just curious about the disadvantageous aspects of OPcache. 
 
 My logic says there must be some issues with it otherwise it would  have come 
 already enabled.   
 
 Sent from iPhone 
 
 
 On Sep 18, 2013, at 2:20 AM, Camilo Sperberg unrea...@gmail.com wrote:
 
 
 On Sep 18, 2013, at 09:38, Negin Nickparsa nickpa...@gmail.com wrote:
 
 Thank you Sebastian..actually I will already have one if qualified for the
 job. Yes, and I may fail to handle it that's why I asked for guidance.
 I wanted some tidbits to start over. I have searched through yslow,
 HTTtrack and others.
 I have searched through php list in my email too before asking this
 question. it is kind of beneficial for all people and not has been asked
 directly.
 
 
 Sincerely
 Negin Nickparsa
 
 
 On Wed, Sep 18, 2013 at 10:45 AM, Sebastian Krebs 
 krebs@gmail.comwrote:
 
 
 
 
 2013/9/18 Negin Nickparsa nickpa...@gmail.com
 
 In general, what are the best ways to handle high traffic websites?
 
 VPS(clouds)?
 web analyzers?
 dedicated servers?
 distributed memory cache?
 
 
 Yes :)
 
 But seriously: That is a topic most of us spent much time to get into it.
 You can explain it with a bunch of buzzwords. Additional, how do you define
 high traffic websites? Do you already _have_ such a site? Or do you
 _want_ it? It's important, because I've seen it far too often, that
 projects spent too much effort in their high traffic infrastructure and
 at the end it wasn't that high traffic ;) I wont say, that you cannot be
 successfull, but you should start with an effort you can handle.
 
 Regards,
 Sebastian
 
 
 
 
 Sincerely
 Negin Nickparsa
 
 
 
 
 --
 github.com/KingCrunch
 
 
 Your question is way too vague to be answered properly... My best guess 
 would be that it depends severely on the type of website you have and how's 
 the current implementation being well... implemented.
 
 Simply said: what works for Facebook may/will not work for linkedIn, twitter 
 or Google, mainly because the type of search differs A LOT: facebook is 
 about relations between people, twitter is about small pieces of data not 
 mainly interconnected between each other, while Google is all about links 
 and all type of content: from little pieces of information through whole 
 Wikipedia.
 
 You could start by studying how varnish and redis/memcached works, you could 
 study about how proxies work (nginx et al), CDNs and that kind of stuff, but 
 if you want more specific answers, you could better ask specific question.
 
 In the PHP area, an opcode cache does the job very well and can accelerate 
 the page load by several orders of magnitude, I recommend OPCache, which is 
 already included in PHP 5.5.
 
 Greetings.
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


The original RFC states: 

https://wiki.php.net/rfc/optimizerplus
The integration proposed for PHP 5.5.0 is mostly 'soft' integration. That means 
that there'll be no tight coupling between Optimizer+ and PHP; Those who wish 
to use another opcode cache will be able to do so, by not loading Optimizer+ 
and loading another opcode cache instead. As per the Suggested Roadmap above, 
we might want to review this decision in the future; There might be room for 
further performance or functionality gains from tighter integration; None are 
known at this point, and they're beyond the scope of this RFC.

So that's why OPCache isn't enabled by default in PHP 5.5

Greetings.


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



Re: [PHP] how old is this version of PHP?

2013-08-17 Thread Camilo Sperberg
On 16 aug. 2013, at 19:17, Tamara Temple tamouse.li...@gmail.com wrote:

 Looking into a problem for someone who is using Godaddy Shared Web Hosting (I 
 know..), I noticed the version tag reported by phpinfo is: 
 
 
 PHP API   20041225
 PHP Extension 20060613
 Zend Extension220060519
 
 Just how old is this version of PHP??
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

According to my google search, it should be 5.2.9, so it isn't that old:


http://devzone.zend.com/1442/compiling-php-extensions-with-zend-server/

CD onto the extension's source dir (in our example, the PHP version is 5.2.9 as 
it is the current stable version Zend Server is shipped with):

$ cd /usr/local/zend/share/php-source/php-5.2.9/ext/pspell
Run phpize:

$ /usr/local/zend/bin/phpize
Output should be similar to this:

/Configuring for:
PHP Api Version: 20041225
Zend Module Api No:  20060613
Zend Extension Api No:   220060519/


Greetings.


Met vriendelijke groet,
Camilo Sperberg


W: http://unreal4u.com
T: http://twitter.com/unreal4u


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



Re: [PHP] What the hell is Begacom?

2013-08-04 Thread Camilo Sperberg


On 4 aug. 2013, at 12:51, Ashley Sheridan a...@ashleysheridan.co.uk wrote:

 And why everytime I reply to the list am I getting an automated reply
 from this email address
 
 Belgacom Webteam [no-reply] supp...@skynet.be
 
 
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 

So that's why I was getting those emails as well xD

Sent from my iPhone 6 Beta [Confidential use only]

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



Re: [PHP] Detect and Redirect Mobile Users

2013-06-14 Thread Camilo Sperberg

On Jun 13, 2013, at 15:31, Camille Hodoul camille.hod...@gmail.com wrote:

 Hello,
 
 I stumbled upon this the other day :
 http://mobiledetect.net/
 I haven't tried it yet, since I have my own small user agent parser when I
 need it, but it may help you if it's a pure php solution you're looking for.
 
 Have a nice day
 
 
 2013/6/13 dealTek deal...@gmail.com
 
 Hi all,
 
 I'm curious of a simple, common, universal way to detect a mobile user so
 I can redirect them to a mobile directory...
 
 What is best for this: Javascript - CSS - PHP?
 
 I think for my purposes if I can detect screen size or mobile browser
 agent - that would be good enough for what I need right now.
 
 Thanks in advance - Dave
 
 
 --
 Thanks,
 Dave - DealTek
 deal...@gmail.com
 [db-3]
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 -- 
 Camille Hodoul
 http://camille-hodoul.com/

Some time ago, I tested php-mobile-detect and detectmobilebrowsers.com, taking 
the (old) wurfl database (as a reference with a bit less than 15.000 mobile 
devices). Tests came out as follows:

php-mobile-detect: 7 seconds in 15.000 devices, 70% accuracy
detectmobilebrowsers.com: 0.6 seconds in 15.000 devices, 93,5% accuracy

The post I made is in spanish, but could serve as a reference:
http://blog.unreal4u.com/2012/10/detectar-facilmente-un-dispositivo-movil/

As for the OP, I think that the best way would be PHP, because you can do a lot 
more, like not even redirecting the user but rather just load the mobile site 
directly, setting a session value if desktop version is forced or not. This 
way, any links would also be interchangeable, making it easier for you to 
implement specific functionality such as send link through email and other 
related things.

Greetings.


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



Re: [PHP] limit access to php page

2013-05-30 Thread Camilo Sperberg
On 30 mei 2013, at 05:05, Paul M Foster pa...@quillandmouse.com wrote:

 On Wed, May 29, 2013 at 08:51:47PM -0400, Tedd Sperling wrote:
 
 On May 29, 2013, at 7:11 PM, Tim Dunphy bluethu...@gmail.com wrote:
 
 Hello list,
 
 I've created an authentication page (index.php) that logs into an LDAP
 server, then points you to a second page that some folks are intended to
 use to request apache redirects from the sysadmin group (redirect.php).
 
 Everything works great so far, except if you pop the full URL of
 redirect.php into your browser you can hit the page regardless of the login
 process on index.php.
 
 How can I limit redirect.php so that it can only be reached once you login
 via the index page?
 
 Thank you!
 Tim
 
 -- 
 GPG me!!
 
 Try this:
 
 http://sperling.com/php/authorization/log-on.php
 
 I realize this is example code.
 
 My question is, in a real application where that $_SESSION['auth'] token
 would be used subsequently to gain entry to other pages, what would you
 use instead of the simple TRUE/FALSE value? It seems that someone (with
 far more knowledge of hacking than I have) could rather easily hack the
 session value to change its value. But then again, I pretty much suck
 when it comes to working out how you'd hack (crack) things.
 
 Paul
 
 -- 
 Paul M. Foster
 http://noferblatz.com
 http://quillandmouse.com
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

$_SESSION value are quite secure, as they are set on the server, only you can 
control what's inside them. What can be hacked is the authentification process 
or some script that sets session values. There is also a way of hijacking a 
session, but again: its values aren't changed by some PHP script, the session 
is being hijacked. Don't pass urls with the session id within them and you'll 
be save. 

Greetings. 

Sent from my iPhone 6 Beta [Confidential use only]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: include() Error

2013-05-29 Thread Camilo Sperberg
You are most probable getting a fatal error, and the way PHP is configured
now, doesn't show you that publicly. Enable that setting via php.ini or
directly in the script (not recommended) or check out the webserver's
error_log (assuming apache and a RedHat based distro this will be on
/var/log/httpd/error_log). This will tell you what is really going on
because we don't even know what mySQL_user_login.inc.php looks like or what
it does, we also don't know what extensions are activated.

Providing that information you'll get more luck getting great answers. Also
try to mention what distro you're using.

Greetings.


On Wed, May 29, 2013 at 8:09 PM, Jim Giner jim.gi...@albanyhandball.comwrote:

 On 5/29/2013 1:39 PM, Ron Piggott wrote:


 Good morning all:

 I have recently purchased a computer and am using it as a dedicated
 server.  A friend helped me install PHP and configure.  I am saying this
 because I wonder if using a newer version of PHP (compared to my commercial
 web host) may be the reasoning behind the error I am receiving.

 I created a function to generate a form submission key.
 - This created hidden variable for forms
 - This is also session variable

 With this function I have an ‘ include ‘ for the file containing the
 mySQL database, username and password.  I know this file is being accessed
 because I added:

 ===
 echo $mySQL_user;
 ===

 following the login credentials.

 But when I remove this line from mySQL_user_login.inc.php and place
 within the function on the line following the include the echo” returns
 nothing.

 ===
 include(mySQL_user_login.inc.**php);

 echo $mySQL_user;
 ===

 Can any of you tell me why this is happening?

 Ron Piggott



 www.TheVerseOfTheDay.info

  #1 - it's not an include error.  It's a programmer error

 #2 - that said - why would you want to do this?  The release of
 usernames/passwords is a dangerous practice - even in development.  If all
 you want to do is verify that you passed thru this bit of code, echo some
 less sensitive message, such as Connected successfully. Or even better
 have the connect function return true or false and check the return.

 #3 - global
 #4 - global
 and #5 global.  Anytime you want to use a var withing a function include
 it in a global statement.

 I always forget too.  But I'm getting pretty good at remembering how to
 resolve it.

 PS - do you store your .inc file with this sensitive info on your server
 outside of the web-accessible path?  I hope so.


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




Re: [PHP] Re: include() Error

2013-05-29 Thread Camilo Sperberg
On Wed, May 29, 2013 at 8:09 PM, Jim Giner jim.gi...@albanyhandball.comwrote:

 On 5/29/2013 1:39 PM, Ron Piggott wrote:


 Good morning all:

 I have recently purchased a computer and am using it as a dedicated
 server.  A friend helped me install PHP and configure.  I am saying this
 because I wonder if using a newer version of PHP (compared to my commercial
 web host) may be the reasoning behind the error I am receiving.

 I created a function to generate a form submission key.
 - This created hidden variable for forms
 - This is also session variable

 With this function I have an ‘ include ‘ for the file containing the
 mySQL database, username and password.  I know this file is being accessed
 because I added:

 ===
 echo $mySQL_user;
 ===

 following the login credentials.

 But when I remove this line from mySQL_user_login.inc.php and place
 within the function on the line following the include the echo” returns
 nothing.

 ===
 include(mySQL_user_login.inc.**php);

 echo $mySQL_user;
 ===

 Can any of you tell me why this is happening?

 Ron Piggott



 www.TheVerseOfTheDay.info

  #1 - it's not an include error.  It's a programmer error

 #2 - that said - why would you want to do this?  The release of
 usernames/passwords is a dangerous practice - even in development.  If all
 you want to do is verify that you passed thru this bit of code, echo some
 less sensitive message, such as Connected successfully. Or even better
 have the connect function return true or false and check the return.

 #3 - global
 #4 - global
 and #5 global.  Anytime you want to use a var withing a function include
 it in a global statement.

 I always forget too.  But I'm getting pretty good at remembering how to
 resolve it.

 PS - do you store your .inc file with this sensitive info on your server
 outside of the web-accessible path?  I hope so.


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



You are most probable getting a fatal error, and the way PHP is configured
now, doesn't show you that publicly. Enable that setting via php.ini or
directly in the script (not recommended) or check out the webserver's
error_log (assuming apache and a RedHat based distro this will be on
/var/log/httpd/error_log). This will tell you what is really going on
because we don't even know what mySQL_user_login.inc.php looks like or what
it does, we also don't know what extensions are activated.

Providing that information you'll get more luck getting great answers. Also
try to mention what distro you're using.

Greetings.

-- 
@unreal4u
http://unreal4u.com/


Re: [PHP] .htaccess and user file/folder access outside public_html

2013-05-25 Thread Camilo Sperberg

On May 25, 2013, at 13:38, Rafnews raf.n...@gmail.com wrote:

 Hi,
 
 i'm facing a problem and i don't know where to start and in fact, how to do 
 it.
 
 Situation:
 Users of my website should be able to save their resume files + cover letters 
 on my webserver.
 
 problem:
 how to make their file SECURED from any hack ? I mean only file owner and web 
 administrator (so in this case... myself) should have access to those files.
 never user B should be able to access, read or download files of user A.
 
 my guess:
 i was thinking to store files outside public_html folder, in the following 
 way:
 
 /resumes/user A/resume A
 /resumes/user A/cover letter A
 
 /resumes/user B/resume B - US
 /resumes/user B/resume B - ES
 /resumes/user B/cover letter B
 
 Questions:
 1. how can i allow user to have access to folder/files outside public_html ?
 2. how can i secure that user A has access to his own files ONLY ?
 
 i searched on internet for some help but i did not find anything really 
 revelent...only theory and no really in details.
 
 I need your help.
 thx.
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


You will have to make a few scripts that check whether User A is logged in or 
not, read the files with PHP, change the default headers and print the output, 
which should be the exact same document. A quick example would be:

?php
// file_exists also checks whether a directory exists
if (!empty($_SESSION['userId'])  
file_exists(dirname(__FILE__).'/../resumes/'.$_SESSION['userId']) {
// all the necesary headers, check out the documentation for header() 
function on php.net
header('(all the needed headers)');
echo 
file_get_contents(dirname(__FILE__).'/../resumes/'.$_SESSION['userId'].'/resume 
A.doc');
}

Above is basic pseudo-code, not tested. Now all you have to care about is that 
userId is correctly set and that nobody can hijack that user account.

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



Re: [PHP] mysql custom global defined variable

2013-03-13 Thread Camilo Sperberg

On Mar 13, 2013, at 10:35 AM, Kevin Peterson wrote:

 In my database design, I tend to store some variable that is meant to be 
 acting as a ROLE or TYPE as SMALLINT. For example : 
 
CREATE TABLE `house` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `type` smallint(11) NOT NULL,
)
 
 
 And in php, I do
 
define('HOUSE_SMALL_TYPE', '0');
define('HOUSE_MEDIUM_TYPE', '1');
 
 So in php, in SELECT queries I do :
 
$this-db-query(SELECT * FROM house  
WHERE type=?;, HOUSE_SMALL_TYPE);
 
 My questions are : 
 1. In the php part, is there is a better way to do this ? 
 2. In the mysql itself, does mysql also has global define functionality (like 
 the define in php) ? I also want to do kind of SELECT * FROM house WHERE type 
 = HOUSE_SMALL_TYPE in mysql query.
 


Question 1:
I see no possible improvements, you could however use an array with values 
instead of constants, but that's rather a personal choice as I don't like 
constants that much, unless you are on your own namespace.

My example implementation:

$houseTypes = array(
'house_small_type' = 0,
'house_medium_type' = 1,
etc.
);

Question 2:
You could use ENUM data type, but it has quite a few disadvantages:
1- Translation could be tricky to implement
2- DDL shouldn't be used for data!
3- Updating or deleting values can leave your old records in an inconsistent 
state

You can also use SET to set variables, I've never used them but I think they 
could work in your case: 
http://dev.mysql.com/doc/refman/5.5/en/user-variables.html

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



Fwd: [PHP] Where do I report bugs/feature requests for Image magick ext

2013-03-12 Thread Camilo Sperberg


Begin forwarded message:

 From: Camilo Sperberg
 Subject: Re: [PHP] Where do I report bugs/feature requests for Image magick 
 ext
 Date: March 12, 2013 1:40:09 PM GMT+01:00
 To: Carsten Jensen to...@tomse.dk
 
 
 On Mar 12, 2013, at 1:13 PM, Carsten Jensen wrote:
 
 As subject says, I'm having some trouble finding out where to report 
 bugs/feature requests for the Image magick extension.
 
 Anyone would be so kind to point me in the right direction please?
 
 cheers
 Carsten
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


Sorry, forgot to reply all:


 I guess you mean the imagick extension, in that case it's bugtracker is 
 located at bugs.php.net: 
 
 https://bugs.php.net/search.php?cmd=displaypackage_name[]=imagicksearch_for=imagemagickproject=php_os=php_os_not=author_email=bug_type=boolean=0bug_age=0bug_updated=0order_by=ts1direction=ASClimit=30phpver=cve_id=cve_id_not=patch=pull=assign=status=Openreorder_by=ts1
 
 If you want to add a new bug, make sure to select package imagick. Search 
 first if it isn't filed in as a bug already.
 
 There is a big difference between imagick (PHP extension) and image magick 
 (the program). Make sure you know where to file in the bug.
 
 Greetings.


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



Re: [PHP] APC opcode cache behavior

2013-02-14 Thread Camilo Sperberg

On 14 feb. 2013, at 15:19, ma...@behnke.biz ma...@behnke.biz wrote:

 Aaron Holmes aa...@aaronholmes.net hat am 14. Februar 2013 um 03:53
 geschrieben:
 Hello,
 I'm trying to find some information on APC opcode cache behavior.
 We noticed an issue where, when switching symlinks to different versions
 of sites, old code was running from the previous version after switching
 the symlink.
 
 Anyone know where I can find more information on this?
 
 Yes, that is the case. And iirc it will not update the cache if the mtime of 
 the
 new switched file is not newer. If you switch you must either restart the
 apache or touch the files.
 
 read more:
 http://linuxaria.com/howto/everything-you-need-to-know-about-apc-alternate-php-cache?lang=en
 
 And on php.net about ini configuration values
 
 
 Thanks,
 Aaron holmes
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 --
 Marco Behnke
 Dipl. Informatiker (FH), SAE Audio Engineer Diploma
 Zend Certified Engineer PHP 5.3
 
 Tel.: 0174 / 9722336
 e-Mail: ma...@behnke.biz
 
 Softwaretechnik Behnke
 Heinrich-Heine-Str. 7D
 21218 Seevetal
 
 http://www.behnke.biz
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


You can also write a little script that clears the APC cache, something in the 
line of: 

#!/usr/bin/php
?php 
apc_clear_cache();

And execute this script each time you deploy. (can also be a command such as 
php -r apc_clear_cache();). This way you'll avoid restarting the webserver 
and it will clear all APC cache forcing APC to cache everything again.

Greetings.

Met vriendelijke groet,
Camilo Sperberg


W: http://unreal4u.com
T: http://twitter.com/unreal4u


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



Re: [PHP] APC opcode cache behavior

2013-02-14 Thread Camilo Sperberg

On 14 feb. 2013, at 20:32, Marco Behnke ma...@behnke.biz wrote:

 Am 14.02.13 16:05, schrieb Camilo Sperberg:
 
 You can also write a little script that clears the APC cache, something in 
 the line of: 
 
 #!/usr/bin/php
 ?php 
 apc_clear_cache();
 
 And execute this script each time you deploy. (can also be a command such as 
 php -r apc_clear_cache();). This way you'll avoid restarting the webserver 
 and it will clear all APC cache forcing APC to cache everything again.
 
 since apache and cli do not share the same apc, it will not work.
 
 -- 
 Marco Behnke
 Dipl. Informatiker (FH), SAE Audio Engineer Diploma
 Zend Certified Engineer PHP 5.3
 
 Tel.: 0174 / 9722336
 e-Mail: ma...@behnke.biz
 
 Softwaretechnik Behnke
 Heinrich-Heine-Str. 7D
 21218 Seevetal
 
 http://www.behnke.biz
 
 

Oh true, sorry, I totally forgot.

In that case, you can always do a wget or cURL request to your server forcing 
it to clean APC cache through the webserver, I assume that if you're deploying 
through symlinks you want a really minimal downtime during update, the only bad 
thing about this method is that you need to protect the script from external 
visitors through htaccess or similar methods if you're using other webservers. 
Make the request like: 
wget http://localhost/apc-clear.php -O /dev/null 21

man wget for more information about how to use always the correct options.


If you are using Apache, you can also give a try with a graceful restart, in 
red hat based systems, you would restart apache with:
/etc/init.d/httpd graceful
or
apachectl graceful

I have never tried this on a production machine so I really don't know if that 
is gonna work, but the idea after this method is to: 
The USR1 or graceful signal causes the parent process to advise the children 
to exit after their current request (or to exit immediately if they're not 
serving anything).
http://httpd.apache.org/docs/2.2/stopping.html#graceful

Hope this helps ^^

Met vriendelijke groet,
Camilo Sperberg


W: http://unreal4u.com
T: http://twitter.com/unreal4u


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



Re: [PHP] Sorry bout that...

2012-12-21 Thread Camilo Sperberg

On 21 dec. 2012, at 14:22, Steven Staples sstap...@mnsi.net wrote:

 I would like to let everyone know that the world didn't end this morning
 like it was supposed too.
 
 
 
 Sorry, carry on about your business.
 
 
 
 And HAPPY FRIDAY!!!
 
 
 
 Steven Staples
 

lol xD

Latest news says it will happen at 21-12-12 23:59 -4 UTC, so don't celebrate 
yet :P

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



Re: [PHP] RAM Disk

2012-10-22 Thread Camilo Sperberg

On 22 okt. 2012, at 04:45, Alan Hoffmeister alanhoffmeis...@gmail.com wrote:

 Hello fellows.
 Have anyone already tested PHP inside RAM disk with some Apache/nginx
 accessing those files or even session files?
 It's just for curiosity and performance analysis.
 
 Thanks.
 
 
 -- 
 --
 Att,
 Alan Hoffmeister

I have not tested it but I think it wouldn't be much difference respecting APC 
for example, maybe a tiny little bit faster reading sessions and other file 
stuff because RAM have really small access times, but database connections and 
stuff would still be your main bottleneck (I'm assuming you do).

I would install APC and set /tmp up into a RAM disc, mainly because not only do 
MySQL write temporary files into /tmp (example: if MySQL decides to create a 
temporary table which would be with almost any grouping you do), also apache 
does and, if you haven't setted up the session routes, sessions will also write 
itself to /tmp. Plus, if your machine happens to suddenly reboot, you won't 
lose any important stuff.

Getting /var/log/ into an SSD or RAM disk should help too, but again: if 
reliability is important to you, I wouldn't do that. 

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



[PHP] Expected behaviour or bug?

2012-09-17 Thread Camilo Sperberg
Hello list, I have a little question with PHP's internal working. I've managed 
to reduce the test to the following lines:

$globalVariable = 'i am a global variable';
function testFunction() {
global $globalVariable;
unset($globalVariable);
}

testFunction();

if(isset($globalVariable)) {
var_dump('global variable IS set');
} else {
var_dump('global variable is NOT set');
}



When executing the above test, you will get printed that the global variable is 
set, despite unsetting it in the function. Is it really the intention to unset 
a global variable inside a function locally or have I just happen to found a 
little bug?

unreal4u-MBP:~ unreal4u$ php --version
PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans

If it is expected behavior, is there any documentation on why this is done this 
way?

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



Re: [PHP] Expected behaviour or bug?

2012-09-17 Thread Camilo Sperberg

On 17 sep. 2012, at 10:55, Frank Arensmeier farensme...@gmail.com wrote:

 17 sep 2012 kl. 10.50 skrev Camilo Sperberg:
 
 Hello list, I have a little question with PHP's internal working. I've 
 managed to reduce the test to the following lines:
 
 $globalVariable = 'i am a global variable';
 function testFunction() {
  global $globalVariable;
  unset($globalVariable);
 }
 
 testFunction();
 
 if(isset($globalVariable)) {
  var_dump('global variable IS set');
 } else {
  var_dump('global variable is NOT set');
 }
 
 
 
 When executing the above test, you will get printed that the global variable 
 is set, despite unsetting it in the function. Is it really the intention to 
 unset a global variable inside a function locally or have I just happen to 
 found a little bug?
 
 unreal4u-MBP:~ unreal4u$ php --version
 PHP 5.3.13 with Suhosin-Patch (cli) (built: Jun 20 2012 17:05:20) 
 Copyright (c) 1997-2012 The PHP Group
 Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
   with Xdebug v2.3.0dev, Copyright (c) 2002-2012, by Derick Rethans
 
 If it is expected behavior, is there any documentation on why this is done 
 this way?
 
 Greetings and thanks.
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 Sometimes, it helps reading the manual...
 
 http://lmgtfy.com/?q=php+unset+global
 
 If a globalized variable is unset() inside of a function, only the local 
 variable is destroyed. The variable in the calling environment will retain 
 the same value as before unset() was called.
 [...]
 To unset() a global variable inside of a function, then use the$GLOBALS 
 array to do so:
 
 Took about 1 minute to find out.
 
 /frank

Doh! Only thing I can say is that I tried searching but without any relevant 
terms… Thanks and also thanks to Simon!

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



Re: [PHP] Depreciation message I can't make out....

2012-06-28 Thread Camilo Sperberg
According to what i can understand from that message is that you have line(s) 
starting with # in your php.ini file. A proper ini file should use ; as the 
beginning from a comment. 

Check the given file at the given line and change the first # symbol into a ; 
one. 

Greetings. 

Sent from my iPhone 5 Beta [Confidential use only]

On 28 jun. 2012, at 19:44, Gary Lebowitz gurqi...@gmail.com wrote:

 Hi,
 
 I am running Moodle 2.2.3 and using PHP 5.3 on a Linux server with GoDaddy
 and am getting the message about depreciation after having typed the
 following command into their cron job manager:
 /web/cgi-bin/php5_3 $HOME/html/moodle223a/admin/cli/cron.php
 
 PHP Deprecated:  Comments starting with '#' are deprecated in
 /web/conf/php5.ini on line 1256 in Unknown on line 0
 PHP Deprecated:  Comments starting with '#' are deprecated in
 /web/conf/php5.ini on line 1257 in Unknown on line 0
 br /
 bDeprecated/b:  Directive 'magic_quotes_gpc' is deprecated in PHP 5.3
 and greater in bUnknown/b on line b0/bbr /
 Content-type: text/html
 
 GoDaddy says that I am using a command that is not adapted to version 5.3
 of PHP, but they suggested I contact you to fix it. Also, I do not believe
 I have access to php5.ini; only they do. But I would need to tell them how
 to fix this issue. And no one at Moodle.org seems to be able to help.
 Perhaps it's a Moodle thing; perhaps not, but I thought it wise to contact
 you. By the way, this message is only sent to me when using version 5.3 of
 PHP; I have another Moodle site using 5.2 and things go perfectly well,
 without this message.
 
 Regards,

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



Re: [PHP] test

2012-06-07 Thread Camilo Sperberg
It seems so

Sent from my iPhone 5 Beta [Confidential use only]

On 7 jun. 2012, at 20:07, Sven Kowalski sven-kowal...@gmx.de wrote:

 does it work now?
 
 -- 
 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] Function size

2012-05-23 Thread Camilo Sperberg
I use a lot of switches but they are always small in size because they look 
mostly like this:

switch($action) {
  case 'hello':
$someObject-executeAction();
break;
  case 'world':
$someOtherObject-executeOtherAction();
break;
  default:
$this-anotherAction();
break;
}

Maybe it's not the rule for some really specific small functionality which I 
know I won't be using ever again, but that's the latest trend I've acquired in 
order to improve readability. Personally I find that the particular switch 
statement disorders the code, but at least it is a lot better than a lot of 
if/elses xD

Haven't you tried this approach or does that particular function do have a lot 
of cases?

Greetings.

On 23 mei 2012, at 21:49, Ashley Sheridan wrote:

 On Wed, 2012-05-23 at 20:59 +0200, Matijn Woudt wrote:
 
 On Wed, May 23, 2012 at 5:49 PM, shiplu shiplu@gmail.com wrote:
 On Wed, May 23, 2012 at 8:14 PM, Tedd Sperling t...@sperling.com wrote:
 
 Hi gang:
 
 On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
 A rule of thumb is no more than 50 lines per
 function, most much less. Back in the day when we didn't have nifty
 gui screens and an 24 line terminals (yay green on black!), if a
 function exceeded one printed page, it was deemed too long and marked
 for refactoring.
 
 You hit upon a theory of mine -- and that is our functions grow in size up
 to our ability to view them in their totality. When our functions get
 beyond that limit, we tend to refactor and reduce.
 
 
 When number of lines becomes the criteria of function size? Wouldn't it
 depends on the task the function is doing? I follow this rule, *Each time I
 end up need a code block I wrote earlier, I convert it to a function. *So
 simple.  This way you re-factor your code automatically and you dont do any
 copy paste.  Last year someone on Stackoverflow asked something like
 this[1]. And that was my answer.
 
 
 
 Hi,
 
 While this could be one reason to start a new function, it should not
 (IMO) be the only reason. Sometimes you can have a large complicated
 function, with say 200 LOC. While I wouldn't need any of these lines a
 second time, I usually try to rip blocks of say 50 lines out and put
 it in a seperate function, so that the main function itself is easier
 to understand.
 
 - Matijn
 
 
 
 I'm of the same mind. Generally I'll split a function if I'm reusing
 more than a couple of lines of code. I only split a large function if
 it's actually doing several things, if it happens to need 200 lines to
 perform one 'step' then I'll leave it as is. While I do prefer my
 functions to fit into a single 'screen', it rarely happens quite like
 that, because I move from screen to screen with different resolutions,
 so there's no constant limit for me.
 
 As a rough example, on a random selection of 27 functions taken from a
 controller on a site I worked on I get these general statistics:
 
 Functions: 27
 Mean lines: 22.5
 Mode lines: 3
 Max lines: 218
 
 The function with 218 lines is a large switch, and it doesn't make sense
 to do it any other way, because it would actually end up less readable.
 
 -- 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 


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



Re: [PHP] Performance / AB issue?

2012-05-11 Thread Camilo Sperberg


Sent from my iPhone 5 Beta [Confidential use only]

On 11 mei 2012, at 07:09, Lars Nielsen l...@lfweb.dk wrote:

 
 
 On 10 mei 2012, at 23:26, Lars Nielsen wrote:
 
 
 
 
 Sent from my iPhone 5 Beta [Confidential use only]
 
 On 10 mei 2012, at 17:40, Matijn Woudt tijn...@gmail.com wrote:
 
 On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen l...@lfweb.dk wrote:
 Hi there,
 
 I have apache-2.22/php 5.3.10 set up on a dedicated server but I have
 a
 strange issue.
 
 I have made a Drupal 7 site with a mysql db.
 
 If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it
 works
 fine.
 If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it
 kills
 apache.
 If I stress-test the site with : ab -c 50 -n 1500
 http://sitename/static.html it works fine.
 
 I have set apache's errorlog to debug. But it writes nothing, either
 in
 the virtualhost or in the server-file.
 
 Can anyone give a hint about what can be wrong?
 
 
 
 What do you mean with 'kills apache', does it terminate apache or does
 apache hang (eg. 100% cpu), and respond normal after the stress test
 is over?
 And what is the index of your site? A php script, or..? Do you have
 ModRewrite redirects etc?
 
 - Matijn
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 Can you visit the site normally? Try less verbosing in apache, that is
 pretty intensive, but as you can benchmark a static file well (with
 moderate high settings), i assume it is some configuration problem in
 drupal.
 
 Greeting.
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 Hi,
 
 I can visit the site normaly, but with 2-3 concurrent ab test it fails.
 seen from 'ps' and 'htop' it seems that both apache and mysql continues
 to
 run normaly but it doesnt respond.
 
 If i run netstat -an after the test it shows this :
 Active Internet connections (servers and established)
 Proto Recv-Q Send-Q Local Address   Foreign Address  State
 tcp0  0 0.0.0.0:22  0.0.0.0:*LISTEN
 tcp0  0 127.0.0.1:250.0.0.0:*LISTEN
 tcp0  0 127.0.0.1:3306  0.0.0.0:*LISTEN
 tcp0  0 0.0.0.0:80  0.0.0.0:*LISTEN
 tcp1  0 x.x.x.x:80x.x.x.x:39237   CLOSE_WAIT
 tcp1  0 x.x.x.x:80x.x.x.x:39236CLOSE_WAIT
 tcp0  0 x.x.x.x:22x.x.x.x:47383ESTABLISHED
 tcp0  0 127.0.0.1:80127.0.0.1:34775
 ESTABLISHED
 tcp1  0 x.x.x.x:80x.x.x.x:39300CLOSE_WAIT
 ESTABLISHED
 tcp0  0 127.0.0.1:34775 127.0.0.1:80
 ESTABLISHED
 tcp0  0 x.x.x.x:80x.x.x.x:39330ESTABLISHED
 tcp6   0  0 :::22   :::*
 LISTEN
 tcp6   0  0 ::1:25  :::*
 LISTEN
 
 So it does seem like there should be room for new tcp connections?
 
 But if I restart apache then it works again... So I guess it is a
 apache/php configuration issue?
 
 --
 Med venlig hilsen / Best Regards
 
 LFWeb
 Lars Nielsen
 Thorsensvej 30
 4800 Nykøbing Falster
 Tlf: +45 20 64 85 76
 email : l...@lfweb.dk
 www : http://www.lfweb.dk
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 Have you tried benchmarking a really simple php page, such as
 
 ?php echo 'hello world'; ?
 
 ?
 
 It that works, than it is definitely an issue in Drupal's configuration
 and not in PHP/Apache. Additionally, you could check what happens when you
 try to establish a session or make a database call to rule out those as
 well, just make really simple tests that you know wouldn't fail and run ab
 on them.
 
 Greetings.
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 Thanks!
 
 Now I have made
 ?php
  echo Hey from PHP!;
 ?
 
 It runs fine from a little concurrency. But with -c 5 -n 500 it fails
 after 308 requests!
 
 
 
 Best Regards / Med venlig hilsen
 
 LFWeb
 Lars Nielsen
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

Have you tried benchmarking from localhost? Do you have any active firewall? 
Selinux? Shorewall? Anything that could block a ddos attack?

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



Re: [PHP] Performance / AB issue?

2012-05-10 Thread Camilo Sperberg


Sent from my iPhone 5 Beta [Confidential use only]

On 10 mei 2012, at 17:40, Matijn Woudt tijn...@gmail.com wrote:

 On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen l...@lfweb.dk wrote:
 Hi there,
 
 I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a
 strange issue.
 
 I have made a Drupal 7 site with a mysql db.
 
 If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works
 fine.
 If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills
 apache.
 If I stress-test the site with : ab -c 50 -n 1500
 http://sitename/static.html it works fine.
 
 I have set apache's errorlog to debug. But it writes nothing, either in
 the virtualhost or in the server-file.
 
 Can anyone give a hint about what can be wrong?
 
 
 
 What do you mean with 'kills apache', does it terminate apache or does
 apache hang (eg. 100% cpu), and respond normal after the stress test
 is over?
 And what is the index of your site? A php script, or..? Do you have
 ModRewrite redirects etc?
 
 - Matijn
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

Can you visit the site normally? Try less verbosing in apache, that is pretty 
intensive, but as you can benchmark a static file well (with moderate high 
settings), i assume it is some configuration problem in drupal. 

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



Re: [PHP] Performance / AB issue?

2012-05-10 Thread Camilo Sperberg

On 10 mei 2012, at 23:26, Lars Nielsen wrote:

 
 
 
 Sent from my iPhone 5 Beta [Confidential use only]
 
 On 10 mei 2012, at 17:40, Matijn Woudt tijn...@gmail.com wrote:
 
 On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen l...@lfweb.dk wrote:
 Hi there,
 
 I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a
 strange issue.
 
 I have made a Drupal 7 site with a mysql db.
 
 If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it
 works
 fine.
 If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it
 kills
 apache.
 If I stress-test the site with : ab -c 50 -n 1500
 http://sitename/static.html it works fine.
 
 I have set apache's errorlog to debug. But it writes nothing, either in
 the virtualhost or in the server-file.
 
 Can anyone give a hint about what can be wrong?
 
 
 
 What do you mean with 'kills apache', does it terminate apache or does
 apache hang (eg. 100% cpu), and respond normal after the stress test
 is over?
 And what is the index of your site? A php script, or..? Do you have
 ModRewrite redirects etc?
 
 - Matijn
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 Can you visit the site normally? Try less verbosing in apache, that is
 pretty intensive, but as you can benchmark a static file well (with
 moderate high settings), i assume it is some configuration problem in
 drupal.
 
 Greeting.
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 Hi,
 
 I can visit the site normaly, but with 2-3 concurrent ab test it fails.
 seen from 'ps' and 'htop' it seems that both apache and mysql continues to
 run normaly but it doesnt respond.
 
 If i run netstat -an after the test it shows this :
 Active Internet connections (servers and established)
 Proto Recv-Q Send-Q Local Address   Foreign Address  State
 tcp0  0 0.0.0.0:22  0.0.0.0:*LISTEN
 tcp0  0 127.0.0.1:250.0.0.0:*LISTEN
 tcp0  0 127.0.0.1:3306  0.0.0.0:*LISTEN
 tcp0  0 0.0.0.0:80  0.0.0.0:*LISTEN
 tcp1  0 x.x.x.x:80x.x.x.x:39237   CLOSE_WAIT
 tcp1  0 x.x.x.x:80x.x.x.x:39236CLOSE_WAIT
 tcp0  0 x.x.x.x:22x.x.x.x:47383ESTABLISHED
 tcp0  0 127.0.0.1:80127.0.0.1:34775
 ESTABLISHED
 tcp1  0 x.x.x.x:80x.x.x.x:39300CLOSE_WAIT 
 ESTABLISHED
 tcp0  0 127.0.0.1:34775 127.0.0.1:80   
 ESTABLISHED
 tcp0  0 x.x.x.x:80x.x.x.x:39330ESTABLISHED
 tcp6   0  0 :::22   :::*LISTEN
 tcp6   0  0 ::1:25  :::*LISTEN
 
 So it does seem like there should be room for new tcp connections?
 
 But if I restart apache then it works again... So I guess it is a
 apache/php configuration issue?
 
 -- 
 Med venlig hilsen / Best Regards
 
 LFWeb
 Lars Nielsen
 Thorsensvej 30
 4800 Nykøbing Falster
 Tlf: +45 20 64 85 76
 email : l...@lfweb.dk
 www : http://www.lfweb.dk
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

Have you tried benchmarking a really simple php page, such as 

?php echo 'hello world'; ?

?

It that works, than it is definitely an issue in Drupal's configuration and not 
in PHP/Apache. Additionally, you could check what happens when you try to 
establish a session or make a database call to rule out those as well, just 
make really simple tests that you know wouldn't fail and run ab on them.

Greetings.


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



Re: [PHP] code deployment through php

2012-05-01 Thread Camilo Sperberg

On 1 mei 2012, at 10:59, rene7705 wrote:

 Hi folks.
 
 I was here a while ago, trying to figure out how to keep deployment
 instances of my common code, running on more than 1 site, in sync with
 eachother.
 
 I've looked at rsync which was recommended here, but didn't like it much,
 nor could I find a good windows version of it.
 
 So yesterday, I decided to try a pure PHP solution. My thinking was: run a
 PHP sync script once on each physical machine that holds possibly multiple
 copies of my common code, and FTP the common code only 1 time because I use
 only 1 shared hosting account besides my windows development machine.
 
 I've gotten it so far that it creates an imo good list of what to copy
 where.
 
 The only problem I can foresee is that the copy command will take more than
 30 seconds, which makes it hard to run at the shared hoster.
 
 And obviously, it's going to need some good input checking to prevent
 abuse.
 
 I've put up a demo at
 http://skatescene.biz/sites/mediabeez.ws/sync_secret_cndj593n2/ , you can
 execute the code job to see it in action.
 
 I'll also post the working copy of my sync library at the bottom of this
 post. The only thing missing is the actual copy($source,$dest), I think.
 
 But, I'm wondering if this is a good approach to code deployment. It
 certainly seems easier and more convenient to me than using rsync. Maybe
 i'm an amateur indeed ;)  Anyways, all criticism is welcome here. Thanks
 for your time! :)
 
 ?php
 function sync_echo_jobs ($path) {
 $jobs = sync_read_jobs ($path);
 echo 'div id=rajmvSync_jobs_json!-- '.json_encode($jobs).' --/div';
 echo 'ul class=rajmvSync_jobs';
 foreach ($jobs['jobs'] as $jobName = $job) {
 echo 'li'.$jobName.' (a
 href=javascript:rscg.executeJob(\''.$jobName.'\');execute/a) (a
 href=javascript:rscg.showEditJobForm(\''.$jobName.'\');edit/a)/li';
 }
 echo '/ul';
 ?
 ?php
 }
 
 function sync_read_jobs ($path) {
 $filepath = $path.'/rajmvSync_jobs.json';
 if (file_exists($filepath)) {
 $r = json_decode (file_get_contents($filepath), true);
 } else {
 $r = array (
 'jobs' = array()
 );
 }
 return $r;
 }
 
 function sync_write_jobs ($path, $jobs) {
 $filepath = $path.'/rajmvSync_jobs.json';
 file_put_contents ($filepath, json_encode($jobs));
 }
 
 function sync_addOrEditJob ($path, $name, $paths) {
 $jobs = sync_read_jobs ($path);
 $jobs['jobs'][$name] = array (
 'paths' = $paths
 );
 sync_write_jobs ($path, $jobs);
 }
 
 function sync_executeJob ($path, $name) {
 $jobs = sync_read_jobs ($path);
 if (array_key_exists($name, $jobs['jobs'])) {
 $job = $jobs['jobs'][$name];
 $paths = explode (\n, $job['paths']);
 // work only on approved paths;
 $pathsApproved = array();
 foreach ($paths as $idx=$pathToSync) {
 $drive = strtolower(substr($pathToSync,0,2));
 if ($drive=='m:') $pathsApproved[]=$pathToSync;
 }
 $paths = $pathsApproved;
 
 // get a list of files for each path to sync with the other paths in the
 same list/var
 $fileLists = array();
 foreach ($paths as $idx = $pathToSync) {
 $fileLists[$pathToSync] = getFilePathList ($pathToSync, true, /(.*)/,
 array('file'));
 }
 // get all the last modified timestamps for each of the found files
 $fileList = array();
 foreach ($paths as $idx = $pathToSync) {
 foreach ($fileLists[$pathToSync] as $idx2 = $filepathToSync) {
 $fileRelativePath = str_replace ($pathToSync, '', $filepathToSync);
 if (!array_key_exists($fileRelativePath, $fileList))
 $fileList[$fileRelativePath] = array();
 $fileList[$fileRelativePath][$pathToSync] = filemtime($filepathToSync);
 }
 }
 // $copyList will hold all the copy commands, initialize;
 $copyList = array();
 foreach ($fileList as $fileRelativePath = $locationResults) {
 foreach ($locationResults as $pathToSync = $filemtime) {
 if (!array_key_exists($fileRelativePath, $copyList))
 $copyList[$fileRelativePath] = array(
 'latest' = null,
 'source' = null,
 'destinations' = array()
 );
 if (is_null($copyList[$fileRelativePath]['latest']) || $filemtime 
 $copyList[$fileRelativePath]['latest']) {
 $copyList[$fileRelativePath]['source'] = $pathToSync;
 $copyList[$fileRelativePath]['latest'] = $filemtime;
 }
 }
 }
 
 // schedule copy command for all files with older filemtime() than the
 latest copy
 foreach ($fileList as $fileRelativePath = $locationResults) {
 foreach ($locationResults as $pathToSync = $filemtime) {
 if ($filemtime  $copyList[$fileRelativePath]['latest']) {
 $copyList[$fileRelativePath]['destinations'][] = $pathToSync;
 }
 }
 }
 // schedule copy command for all new files that must go to all $pathToSync
 where it is not present yet:
 foreach ($copyList as $fileRelativePath = $fileRec) {
 if (count($fileList[$fileRelativePath])!=count($paths)) {
 foreach ($paths as $idx=$pathToSync) {
 if (!array_key_exists($pathToSync, $fileList[$fileRelativePath]))
 $copyList[$fileRelativePath]['destinations'][] = $pathToSync;
 }
 }
 }
 
 // debug output of actual copy commands
 foreach ($copyList as $fileRelativePath = $fileRec) {
 if 

Re: [PHP] Randomly unable to read set variable from class

2012-03-13 Thread Camilo Sperberg
Sorry wasn't able to reproduce it on my test machine. 

Do you have any external modules loaded such as APC, memcached, xDebug maybe or 
other that can affect the output on that machine?

Greetings

On 13 Mar 2012, at 17:02, Adrian Basalic wrote:

 I have an issue that occurs randomly on a machine. After a number of reloads
 of the page i can't read $this-_foo although it is set (var_dump shows it
 but the script cannot read it). The code works locally and on other machines
 i tested. Apache restart seems to fix it but only temporary.
 
 Environment:
 
 . PHP Version 5.3.3
 
 . Linux 2.6.32-220.2.1.el6.x86_64 #1 SMP Fri Dec 23 02:21:33 CST
 2011 x86_64
 
 . Apache 2.0
 
 
 
 class  FooBar
 
{
 
  protected $_foo;
 
  public function setFoo($bar)
 
  {
 
if (!$bar) {
 
  print_r(Cannot find bar);
 
}
 
$this-_foo = $bar;
 
if (!$this-_foo) {
 
  print_r(Cannot read {$this-_foo} set with $bar);
 
  var_dump($this);
 
}
 
var_dump($this);
 
return $this;
 
  }
 
}
 
 
 
$foobar = new FooBar;
 
$foobar-setFoo('bar');
 
 
 
 The output when this happens would be:
 
 
 
 Cannot read set with barobject(FooBar)#1 (1) { [_foo:protected]=
 string(3) bar } object(FooBar)#1 (1) { [_foo:protected]= string(3)
 bar }
 
 
 
 I'm going nuts here, and nobody seems to be able to reproduce this. Where
 should I start looking?
 


___
Mi blog
CHW
Mi Twitter


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



Re: [PHP] Test

2012-02-20 Thread Camilo Sperberg
It's alvvve!!!

Sent from my iPhone 5 Beta [Confidential use only]

On 20 feb. 2012, at 21:08, Jason Pruim li...@pruimphotography.com wrote:

 Someone finally got off their butt and got some work done? ;)
 
 And I have today off for Washingtons birthday! 
 
 
 
 On Feb 20, 2012, at 2:59 PM, Jay Blanchard 
 jay.blanch...@sigmaphinothing.org wrote:
 
 I'll be darned - it finally works. What's up with that?
 
 On Feb 20, 2012, at 1:49 PM, Daniel Brown wrote:
 
 On Mon, Feb 20, 2012 at 14:40, Bastien phps...@gmail.com wrote:
 Definitely doesn't work
 
  The list works just fine, it's you goofs who need to work now!  ;-P
 
 -- 
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.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 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] Finding and reading firefox bookmarks with PHP

2011-11-27 Thread Camilo Sperberg
You can export the bookmarks as a json or html and then read it easily with php 
but i suspect you want to read the firefox files directly, in which case you 
can read the sqlite file called places.sqlite

More info here:
http://support.mozilla.com/en-US/kb/Profiles

Sent from my iPhone 5 Beta [Confidential use only]

On 28 nov. 2011, at 00:47, David McGlone da...@dmcentral.net wrote:

 Hi all, I am wondering if it's possible to find the bookmarks file in
 firefox and output the contents on a page with PHP.. I'm wanting to do
 this so I can use it as my home page.
 -- 
 Thanks,
 David M.
 
 
 -- 
 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] Dreaded Premature end of script headers

2011-08-26 Thread Camilo Sperberg
I had the same problem the other day and it was because a certain index in an 
array didn't exist, this array was constructed from the db and later i was 
trying to access this array.

So my best guess would be that if it happens only at production and db data is 
involved, i would definitly think in arrays, indexes, limits, etc.

Sent from my iPhone 5 Beta [Confidential use only]

On 26-08-2011, at 19:49, tamouse mailing lists tamouse.li...@gmail.com wrote:

 On Fri, Aug 26, 2011 at 6:48 PM, tamouse mailing lists
 tamouse.li...@gmail.com wrote:
 On Fri, Aug 26, 2011 at 1:42 PM, Geoff Shang ge...@quitelikely.com wrote:
 I put this into Google and got this:
 http://htmlfixit.com/cgi-tutes/tutorial_Common_Web_dev_error_messages_and_what_they_mean.php#premature
 
 
 Yeah, I saw that too. I do know the mechanism that is happening. I
 just can't figure out where the problem is without inserting print
 statements.
 
 Presumably, you are calling this cron job with some process which runs the
 PHP script through a URL on your webserver.
 
 Yes, that is correct. Using curl to launch the script via the web server.
 
 1.  Modify the script so that it does actually output something, thereby
 making the error go away.
 
 
 When the script starts, it prints a banner with the script name and
 date/time stamp. When it completes, it is supposed to print aggregate
 results, time spent. I know it's encountering this problem before it
 reaches the end as not all the data gets processed. I can't tell where
 it is stopping though. If I put it in debug mode, it prints out a lot
 of data from the beginning of the script, and never encounters this
 problem.
 
 2.  Run the script directly with PHP instead of via your webserver.  E.g.:
 php -f yourscriptname
 
 The way the script is designed, it depends on some $_SERVER values,
 which wouldn't be set if running directly from the shell.
 
 
 Again, I want to say that this script does NOT fail in dev, test and
 stage, only production.
 
 -- 
 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] regex or 'tidy' script to fix broken ? tags and introspection of variables

2011-08-10 Thread Camilo Sperberg

On 10-08-2011, at 16:54, Daevid Vincent wrote:

 -Original Message-
 From: Camilo Sperberg [mailto:unrea...@gmail.com]
 Sent: Tuesday, August 09, 2011 5:27 PM
 
 For the first one, it may be that zend studio does have an internal script
 to do the job. Check the general preferences tab, template stuff. 
 
 Nope. Nothing there. Those templates are for when you create new blurbs of
 code, not modifying existing code.
 
 There is a formatter however, sadly it doesn't have an option to force these
 (you'd think that would be the perfect place to do this too huh.) In fact, I
 posted this here:
 
 http://forums.zend.com/viewtopic.php?f=59t=19173#p59348

That is sad to hear, I have never done the same thing you are now, but I 
thought it could help.

 
 Many people mistakenly think that short version is going to be deprecated
 away. It is not. The PHP Devs have already clarified only the ? version
 is, not this one.
 
 http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
 

I had no idea, I thought short tags also implied short if-else, short echo and 
so on, good to know that, thanks for the clarification ;)

 
 Second question: zend studio displays all variables used by a script by
 clicking the arrow next to te file name. 
 
 I've used ZS for 4+ years now, and comicaly have never even used those
 little down arrows next to a file. HAHAH! Good to know. Although it is a
 little strange as they seem to only be where you use a = assignment. It
 doesn't know about - or other instances of that variable (like if you
 echo it or something). But still could prove useful.

Eclipse/Zend Studio is so full of options that you can miss a lot of them. 
Another downside of the little arrow thing is that it doesn't recognize arrays, 
which is obvious because arrays can only be read on runtime, well, same thing 
as objects.

 
 If you want to display it in runtime, you can: print_r($GLOBALS);
 
 Whoa nelly! That prints out WAAY too much information ;-)
 
 But thanks. Not sure why I didn't think of that one. Maybe because at one
 time I did use it, got sensory overload from the amount of data it spews to
 the page, and then blocked it out of my mind for future use. :)

Yeah I know it displays a lot of information, but I use it sometimes and it's 
the only way I know to display all variables, arrays and stuff in a neat and 
nice way. You can also install xDebug and use the included debugger in ZS, but 
sometimes using a simple print_r is faster.

Greetings :)

___
Mi blog
CHW
Mi Twitter


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



Re: [PHP] regex or 'tidy' script to fix broken ? tags and introspection of variables

2011-08-09 Thread Camilo Sperberg
For the first one, it may be that zend studio does have an internal script to 
do the job. Check the general preferences tab, template stuff. Please note that 
?= is also valid and should be replaced to ?php echo instead. Also the 
short if version 1 == 1 ? True : false should be replaced if i'm correct.

Second question: zend studio displays all variables used by a script by 
clicking the arrow next to te file name. If you want to display it in runtime, 
you can:
print_r($GLOBALS);

Sent from my iPhone 5 Beta [Confidential use only]

On 09-08-2011, at 19:40, Daevid Vincent dae...@daevid.com wrote:

 I've inherited a bunch of code and the previous developers have done two
 things that are really bugging me and I want to clean up.
 
 [a] They use short-tag ? instead of ?php. Anyone have some good
 search/replace style Regex (ideally for ZendStudio/Eclipse) that will run
 through all the files in the project and fix those? There are lots of cases
 to account for such as a space after the ? or nospace or a newline or even
 other text (which are all valid cases).
 
 [b] The other thing they do use use register_globals in the php.ini file. Is
 there a good way to see all the variables that a page uses? Something I can
 print at the bottom of the page on my dev box - ideally with enough
 introspection to know where that variable originated from, and then I can
 start converting things to $_GET, $_POST,  $_SESSION, $_COOKIE, etc.
 

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



Re: [PHP] Help needed with php.ini

2011-06-05 Thread Camilo Sperberg
On 05-06-2011, at 10:31, Adam Tong adam.to...@gmail.com wrote:

 Hi,
 
 I can't set correctly the error display and reporting properties. I
 don't know what i'm doing wrong.
 
 Here is the section that i modified in php.ini:
 -
 display_errors = On
 ;   Default Value: On
 ;   Development Value: On
 ;   Production Value: Off
 
 display_startup_errors = On
 ;   Default Value: Off
 ;   Development Value: On
 ;   Production Value: Off
 
 error_reporting = E_ALL | E_STRICT
 ;   Default Value: E_ALL  ~E_NOTICE
 ;   Development Value: E_ALL | E_STRICT
 ;   Production Value: E_ALL  ~E_DEPRECATED
 
 
 And here is the output of phpinfo():
 -
 display_errorsOffOff
 display_startup_errorsOffOff
 doc_rootno valueno value
 docref_extno valueno value
 docref_rootno valueno value
 enable_dlOffOff
 error_append_stringno valueno value
 error_logno valueno value
 error_prepend_stringno valueno value
 error_reporting2252722527
 -
 
 I'm using a default installation (using yum) of php on Fedora14. This
 is my development environment, and want to see all the errors on
 standard output.
 
 Thank you
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


Have you modified the example values instead of the ones mid-way php.ini? If 
so, scroll down to check. The latest settings should override the previous one.

Have you restarted apache with service httpd restart or /etc/init.d/httpd 
restart? (or apachectl restart)

In your php script or htaccess file, do you override those values?

Sent from my iPhone 5 Beta [Confidential use only]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Gentle (Friday) Reminder

2011-05-06 Thread Camilo Sperberg
What do you mean by that? (irony lvl: 100%)

Sent from my iPhone

On 06-05-2011, at 22:58, Daniel Brown danbr...@php.net wrote:

 ?php
 
$posting = array('bottom','interspersed','top');
 
// Feel free to add on
$destinations = array('to hell','away','read the archives and see
 why we don\'t like top-posting','to disneyland then die','anywhere
 but here');
 
$point = array_rand($destinations);
 
foreach ($posting as $p) {
 
if ($p == 'top') {
 
// @todo - remind folks of rules: http://links.parasane.net/fb6k
echo 'Just remember top-posting on the list means you
 can go '.$destinations[$point].'.'.PHP_EOL;
 
}
}
 ?
 
 -- 
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.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



Re: [PHP] XML... Useful or another layer of complexity?

2011-04-03 Thread Camilo Sperberg

El 03-04-11 14:41, Jason Pruim escribió:

So the subject says it all... And yes I know this isn't related to PHP but it's 
the weekend and I trust the opinions on this list more then any other list I 
have seen. I've been doing alot of reading on XML and honestly it looks pretty 
cool... BUT the question is... Is it truly useful or is it just another layer 
that we have to write?

 From what I can tell it looks like it could stabilize some of my programming 
in regards to databases, and possibly if I have to move information from one 
application to another.

But is it worth the added coding or should I just interact with the pieces 
directly?

Thoughts? Questions? Flames? :)
I think it is pretty useful, not for internals, but to communicate with 
other apps such as Adobe Flash or any other system which involves 
trespassing information.


SimpleXML is very easy to work with, you'll only need a valid XML file 
to read in case of reading. If you need CDATA support, SimpleXML can be 
extended with this:

http://coffeerings.posterous.com/php-simplexml-and-cdata

Greetings.

--
unreal4u.com http://unreal4u.com/
CHW http://www.chw.net/
Mi Twitter http://twitter.com/unreal4u


Re: [PHP] Correct file permissions for a website

2011-02-15 Thread Camilo Sperberg
On Tue, Feb 15, 2011 at 08:35, Ashim Kapoor ashimkap...@gmail.com wrote:

 Dear All,

 The book PHP and MySQL bible says that the php directory should be world
 executable  ? I remember posting a different question earlier to this list
 and one person suggesting this and another person replying that that was
 incorrect.

 Could someone clear the smoke on this one ?

 Many thanks,
 Ashim.


I would say that depends on your server configuration. If you have suPHP,
the user executing PHP will be yourself, so 744 isn't needed and you can
just leave 700. (Or less, configuration files are usually 400, just read
access).

If the user is Apache (and Apache is in the same group you are), he will
need to read your files, so you should at least have 740 and also he will
need execution rights on the directory which will result in 750. If apache
isn't in the same group you are (most probably scenario) you will need 755.
Strictly speaking, it should be 705.

Greetings.

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Cross-platform IDE

2011-01-26 Thread Camilo Sperberg
I like eclipse as well, you can combine it with svn which will be a great plus 
if you develop on several machines.

Sent from my iPhone

On 26-01-2011, at 10:06, Andy McKenzie amckenz...@gmail.com wrote:

 Hey folks,
 
Hopefully this is enough on-topic not to annoy anyone.  Up until
 now I've mostly written small one-off scripts -- a web page that needs
 a few things dynamically generated, a shell script to do a small job,
 things like that -- and vim has been more than adequate.  I'm
 currently working on something a lot more complex -- a web based
 front-end for a medium sized custom database -- and I'm finding that
 my code is getting more and more scattered because I don't have a good
 tool for looking at it.
 
   So:  does anyone have a recommendation for an IDE that works in
 Windows, Mac, and Linux?  I spend roughly equal time in all three, and
 I haven't found a tool I like yet that works in all of them.
 Actually, I stopped looking three or four years ago, but at that point
 there didn't seem to be anything.  If anyone has any advice, I'd love
 to hear it!
 
 Thanks,
  Alex
 
 -- 
 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] How to get cpu consumption of a php script

2011-01-17 Thread Camilo Sperberg
Please take into account that lighttpd does have some random high 
cpu-consumption problems, it could be that also. Give nginx a try instead. 

Also: microtime by itself isn't enough, sum time() to it because if a script 
lasts more than 1 second you can end up with negative total time, microtime 
doesn't have a seconds counter, only microseconds.

Are you using a cms? Have you tried deactivating some plugins?

Sent from my iPhone

On 17-01-2011, at 7:23, Tanoor Dieng newstan...@gmail.com wrote:

 Hi everybody,
 I'm a php developper for a high traffic website. Our web servers run with
 lightty?
 
 We have some issues with the cpu consumption of our servers.
 
 The problem is that, we don't know exactly which script consumes so much
 cpu.
 So, we cant to figure out how much cpu does a php script take.
 
 We have tried 3 methods:
 
 1) Microtime: microtime at the beginning and at the end and make the diff.
 The problem with that is that it takes the execution time of the script, but
 in our script we make:
 - connection to database
 - connection to memcache
 - connection to session server
 
 All of this is not taken into account, so microtime is not that accurate
 
 2) Shell command: we get the pid of the process executing the script and
 make a 'top' on this pid . The problem  is that the php-cgi manages many
 threads so it's not accurate too.
 
 Is there other methods for dealing with this problem.
 
 Thanks,
 best regards,
 
 Tanoor.

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



Re: [PHP] projectpier

2011-01-12 Thread Camilo Sperberg
At least now we all know of the domainname change xD

Sent from my iPhone

On 12-01-2011, at 19:38, Peter Lind peter.e.l...@gmail.com wrote:

 2011/1/12 Ashley Sheridan a...@ashleysheridan.co.uk
 
 On Wed, 2011-01-12 at 23:14 +0100, Peter Lind wrote:
 
 jeg har flyttet projectpier over paa fastaval.dk domaenet -
 det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
 fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
 (og dermed ikke logge ind det forkerte sted)
 
 
 I think perhaps your change in domains was not meant to be posted to the
 list? :p
 
 
 There's a massive ooops! if ever I did see one. Sorry about the (unintended)
 noise and thanks for letting me know.

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



Re: [PHP] Could this be a bug?

2010-09-14 Thread Camilo Sperberg
Well, after some more testing I'm almost sure it is some kind of strange
minor bug... so I've submitted a bug report:
http://bugs.php.net/bug.php?id=52833

Greetings !

On Tue, Sep 14, 2010 at 00:51, Camilo Sperberg unrea...@gmail.com wrote:


 On Mon, Sep 13, 2010 at 18:56, Tamara Temple tamouse.li...@gmail.comwrote:

 This isn't to answer your question, but...


 On Sep 13, 2010, at 5:16 PM, Camilo Sperberg wrote:

 function my_error_handler($errno = '0', $errstr = '[FATAL] General
 Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) {
   ini_set('memory_limit','16M');
   ob_start();
   echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
 ?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
 25pxemError Ndeg;:/embr /?php
  echo 'strong'.$errno.'/strongbr /';
 ?emError Detail:/embr /?php
   echo 'strong'.$errstr.'/strongbr /emFile:/embr
 /strong'.$errfile.'/strongbr /emLine:/embr
 /strong'.$errline.'/strongbr /emDebug:/embr /';
   if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
 WHAT SHOULD IT RETURN?/p';
 ?/ph4-- END COPY --/h4?php
   $content = ob_get_contents();
   ob_end_clean();
   die($content);
  }
 }


 Why do you put ?php echo...? inside an echo statement in php space?



 I think you may have mis-readed the code, I can't find where I put an ?php
 echo inside an echo. I do a lot of opening/closing tags which contributes to
 messing things up estetically but it works...

 Any way, the posted code had a lot of remniscants of the production code,
 here is a simplified version which does the same as above but .. well,
 simplified :P

 ?php
 date_default_timezone_set('America/Santiago');
 ini_set('memory_limit','1M');
 ini_set('display_errors',1);
 error_reporting(-1);

 function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {
   global $clean_exit;
   if(empty($clean_exit)) { // if isset or !empty, the script would have
 been exited cleanly.
 ini_set('memory_limit','16M'); // This would be just to have enough
 memory to print out the error.
 echo 'h5-- BEGIN ERROR --/h5Error Ndeg;:
 strong'.$errno.'/strongbr /Error Description:
 strong'.$errstr.'/strongbr /File: strong'.$errfile.'/strongbr
 /Line: strong'.$errline.'/strong';
 if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
 WHAT SHOULD IT RETURN?/p'; // isset or empty gives the same error
 echo 'h5-- END ERROR --/h5';
 die(); // shutdown_function == manual die() or else it will continue to
 execute.

   }
 }
 set_error_handler('my_error_handler');
 register_shutdown_function('my_error_handler');

 for ($i = 0; $i  15000; $i++) $a[$i] = mt_rand(1,255);
 $r['print'] = (string)$a[1]; // Just to asign something to that variable.

 echo 'pEverything fine./p';
 $clean_exit = TRUE;


 Greetings :)

 --
 Mailed by:
 UnReAl4U - unreal4u
 ICQ #: 54472056
 www1: http://www.chw.net/
 www2: http://unreal4u.com/




-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Could this be a bug?

2010-09-14 Thread Camilo Sperberg
On Tue, Sep 14, 2010 at 02:46, Thijs Lensselink d...@lenss.nl wrote:

  On 09/14/2010 08:33 AM, Thijs Lensselink wrote:

  On 09/14/2010 12:16 AM, Camilo Sperberg wrote:

 I have some really strange behaviour going on here, and I think it could
 be
 a (minor) PHP's bug.
 I am not really sure about what happens internally, but my best guess
 would
 be that after a memory exhaustion, when I try to execute a custom error
 handler with the register_shutdown_function (which is executed even after
 a
 fatal error) and try to access the element that provoked the memory
 exhaustion, no error should raise instead of *Uninitialized string
 offset:
 0.

 I have prepared a little test case to reproduce the error and (I hope)
 can
 explain the error.

 ?php
 date_default_timezone_set('America/Santiago');
 ini_set('memory_limit','1M');
 ini_set('display_errors',1);
 error_reporting(-1);

 function my_error_handler($errno = '0', $errstr = '[FATAL] General
 Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {


 This seems to be your error. You set $errctx to be a string. But later on
 you use it as an array.
 Remove the = '' part. And it will function as expected.


You're right... However I don't like leaving non-default value in functions
so I did something like if(empty($errctx)) $errctx = array() in the first
line of the custom error handler which threw out the error message and
everything works ok now.

But -and correct me if I'm wrong- isn't isset (or empty) supposed to return
a FALSE whenever that variable doesn't exist?

With your help, I could reduce the test case into:

$asdf = 'hello world';
if (empty($asdf[4]['inventing'])) echo 'nice little world';
if (isset($asdf['inventing'][6])) echo 'little nice world';
// This works ok.

$asdf = '';
if (empty($asdf[4]['inventing'])) echo 'nice little world';
if (isset($asdf['inventing'][6])) echo 'little nice world';
// This returns E_NOTICE

Shouldn't these 2 examples work exactly the same way? (AKA as Nº 1). If
not... why not? Both are string types, onyl difference is that one has no
characters in it while the other does, but essentialy they are both the
same.

Greetings !

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


[PHP] Could this be a bug?

2010-09-13 Thread Camilo Sperberg
I have some really strange behaviour going on here, and I think it could be
a (minor) PHP's bug.
I am not really sure about what happens internally, but my best guess would
be that after a memory exhaustion, when I try to execute a custom error
handler with the register_shutdown_function (which is executed even after a
fatal error) and try to access the element that provoked the memory
exhaustion, no error should raise instead of *Uninitialized string offset:
0.

I have prepared a little test case to reproduce the error and (I hope) can
explain the error.

?php
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
ini_set('display_errors',1);
error_reporting(-1);

function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
$errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) {
ini_set('memory_limit','16M');
ob_start();
echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
25pxemError Ndeg;:/embr /?php
  echo 'strong'.$errno.'/strongbr /';
?emError Detail:/embr /?php
echo 'strong'.$errstr.'/strongbr /emFile:/embr
/strong'.$errfile.'/strongbr /emLine:/embr
/strong'.$errline.'/strongbr /emDebug:/embr /';
if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
WHAT SHOULD IT RETURN?/p';
?/ph4-- END COPY --/h4?php
$content = ob_get_contents();
ob_end_clean();
die($content);
  }
}
set_error_handler('my_error_handler');
register_shutdown_function('my_error_handler');

for ($i = 0; $i  1; $i++) $a[$i] = mt_rand(1,254);
$r['print'] = print_r($a,TRUE);
echo 'pEverything fine./p';

$clean_exit = TRUE;

*
Would this be a bug or is this expected behaviour? I have tested this on PHP
v5.2.14, I've not tested it yet on 5.3.3, but I guess it would have the same
behaviour.

Greetings!

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Could this be a bug?

2010-09-13 Thread Camilo Sperberg
On Mon, Sep 13, 2010 at 18:56, Tamara Temple tamouse.li...@gmail.comwrote:

 This isn't to answer your question, but...


 On Sep 13, 2010, at 5:16 PM, Camilo Sperberg wrote:

 function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
 $errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) {
   ini_set('memory_limit','16M');
   ob_start();
   echo 'h1PHP v'.PHP_VERSION.', error Ndeg; '.$errno.'/h1';
 ?h4-- BEGIN COPY --/h4p style=font-size:110%;margin:50px 0 20px
 25pxemError Ndeg;:/embr /?php
  echo 'strong'.$errno.'/strongbr /';
 ?emError Detail:/embr /?php
   echo 'strong'.$errstr.'/strongbr /emFile:/embr
 /strong'.$errfile.'/strongbr /emLine:/embr
 /strong'.$errline.'/strongbr /emDebug:/embr /';
   if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
 WHAT SHOULD IT RETURN?/p';
 ?/ph4-- END COPY --/h4?php
   $content = ob_get_contents();
   ob_end_clean();
   die($content);
  }
 }


 Why do you put ?php echo...? inside an echo statement in php space?



I think you may have mis-readed the code, I can't find where I put an ?php
echo inside an echo. I do a lot of opening/closing tags which contributes to
messing things up estetically but it works...

Any way, the posted code had a lot of remniscants of the production code,
here is a simplified version which does the same as above but .. well,
simplified :P

?php
date_default_timezone_set('America/Santiago');
ini_set('memory_limit','1M');
ini_set('display_errors',1);
error_reporting(-1);

function my_error_handler($errno = '0', $errstr = '[FATAL] General Error',
$errfile = 'N/A', $errline = 'N/A', $errctx = '') {
  global $clean_exit;
  if(empty($clean_exit)) { // if isset or !empty, the script would have been
exited cleanly.
ini_set('memory_limit','16M'); // This would be just to have enough
memory to print out the error.
echo 'h5-- BEGIN ERROR --/h5Error Ndeg;:
strong'.$errno.'/strongbr /Error Description:
strong'.$errstr.'/strongbr /File: strong'.$errfile.'/strongbr
/Line: strong'.$errline.'/strong';
if (isset($errctx['r']['print'])) echo 'pTHIS LINE GIVES THE ERROR,
WHAT SHOULD IT RETURN?/p'; // isset or empty gives the same error
echo 'h5-- END ERROR --/h5';
die(); // shutdown_function == manual die() or else it will continue to
execute.
  }
}
set_error_handler('my_error_handler');
register_shutdown_function('my_error_handler');

for ($i = 0; $i  15000; $i++) $a[$i] = mt_rand(1,255);
$r['print'] = (string)$a[1]; // Just to asign something to that variable.
echo 'pEverything fine./p';
$clean_exit = TRUE;

Greetings :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


[PHP] Regular expressions, filter option1 OR option2

2010-08-18 Thread Camilo Sperberg
Hello list :)

Just a short question which I know it should be easy, but I'm no expert yet
in regular expressions.
I've got a nice little XML string, which is something like this but can be
changed:

?xml version=1.0 encoding=utf-8?
boolean xmlns=http://tempuri.org/;false/boolean

The boolean value can be true or false, so what I want to do, is filter it.
I've done it this way, but I know it can be improved (just because I love
clean coding and also because I want to master regular expressions xD):

  $result = preg_match('/true/',$curl_response);
  if ($result == 0) $result = preg_match('/false/',$curl_response);

I've also tried something like:
$result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
true OR not false = replace with empty

and also '/^true|^false/' which doesn't seem to work.

Any ideas to filter this kind of string in just one expression?

Thanks in advance :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Regular expressions, filter option1 OR option2

2010-08-18 Thread Camilo Sperberg
On Wed, Aug 18, 2010 at 15:01, Ashley Sheridan a...@ashleysheridan.co.ukwrote:

  On Wed, 2010-08-18 at 23:36 +0530, Shreyas Agasthya wrote:

 Camilo,

 What exactly are you trying to achieve? Meaning:

 if (true)
do this;
 if (false)
do that;

 However, here's a link that I used long back to help me with some RegEx 
 :http://www.gskinner.com/RegExr/

 Regards,
 Shreyas

 On Wed, Aug 18, 2010 at 11:31 PM, Camilo Sperberg 
 csperb...@unreal4u.comwrote:

  Hello list :)
 
  Just a short question which I know it should be easy, but I'm no expert yet
  in regular expressions.
  I've got a nice little XML string, which is something like this but can be
  changed:
 
  ?xml version=1.0 encoding=utf-8?
  boolean xmlns=http://tempuri.org/;false/boolean
 
  The boolean value can be true or false, so what I want to do, is filter it.
  I've done it this way, but I know it can be improved (just because I love
  clean coding and also because I want to master regular expressions xD):
 
   $result = preg_match('/true/',$curl_response);
   if ($result == 0) $result = preg_match('/false/',$curl_response);
 
  I've also tried something like:
  $result = preg_replace('/^(true)|^(false)/','',$curl_response); // if not
  true OR not false = replace with empty
 
  and also '/^true|^false/' which doesn't seem to work.
 
  Any ideas to filter this kind of string in just one expression?
 
  Thanks in advance :)
 
  --
  Mailed by:
  UnReAl4U - unreal4u
  ICQ #: 54472056
  www1: http://www.chw.net/
  www2: http://unreal4u.com/
 





 As far as I can tell, are you just trying to grab the content from the
 boolean tag text node? If it's limited to this basic example, there's
 likely not much of a need to use dedicated DOM functions, but consider using
 them if you need to work on more complex documents.

 If you are just trying to determine if the value is indeed true or false
 and nothing else, then a regex could be overkill here. As you only need to
 check two values, consider:

 if(strpos($xml, 'true') || strpos($xml, 'false'))
 {
 // text node content is OK
 }
 else
 {
 // bad, bad input, go sit in the corner
 }


Indeed Ashley, I'm trying to get the TRUE / FALSE value from the boolean
tag.

After reading again, you're absolutely right: strpos does just what I need
it to do: a simple search for a true or false. (Or null, in which case
strpos will be FALSE anyway).

Thanks for your suggestion, I was doing an overkill here.

@Shreyas: thanks for the link! It is very helpful to speed up the testing a
bit!

Greetings!


-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] In what scenario an extension of a class is useful?

2010-06-29 Thread Camilo Sperberg
On Wed, Jun 23, 2010 at 02:58, Rene Veerman rene7...@gmail.com wrote:

 inheritance of this kind is useful if you have common descendants for
 specific types of object


Nice thought. I imagine something like a DB wrapper, and implementing things
such as multiqueries and others on an extension based on the basic
connection made in the original class. Am I right on that?


 another use, is a modification of a certain component.
 descend it from the parent object and override the functions.
 you can do pre processing and post processing by overriding functions.


So, you're saying I can do something like this? :

class foo {
  function hello($a = '') {
echo 'hello '.$a;
  }
}

class bar extends foo {
  function hello($a = '') {
if (!empty($a)) parent::hello($a);
else echo 'bye world';
  }
}

$xx = new bar();
$xx-hello('asdf');
$xx-hello();

Which will print (hopefully, haven't test it yet):

hello asdf
bye world

That would be really a nice way of updating certain vital apps, without
breaking basic functionality.

Thanks for your answer :)

Greetings !!

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


[PHP] In what scenario an extension of a class is useful?

2010-06-22 Thread Camilo Sperberg
Hello everybody :)

I'm really intrigued on something... In what real-world applications could
an extension of a class be really useful?

Let's say I have this code:

class foo {
  function hello_world($a) {
echo 'foo hello world';
  }

  function bye_world() {
echo 'foo bye world';
  }
}

class bar extends foo {
  function hello_world($a,$b) {
echo 'bar hello world';
  }
}

Point 1: Why not just overwrite the hello_world method in the foo class in
the first place? Wouldn't that save code and possible incompatibility or
consistency issues between the code you've already written and between the
two classes ? (Assuming that you do some things based on the $a and $b
values).

Point 2: On the other hand, maybe I could apply different operations to both
(e.g.: return 1 in foo and 2 in bar), without breaking the basic
functionality already achieved in the foo class. (Maybe considering that I
want to apply an update or patch to an already existing application,
however, is this is the scenario, I should always fix the old code wherever
I invoke the foo class which returns us to point 1).

Point 3: Ok, maybe I don't want a specific class to be so huge and I
separate it into pieces of classes. But then again, wouldn't it be simpler
to just save some code and keeping only one file with the entire class?

Is it just that or do I miss something else? I'm not saying it is useless,
it sounds indeed fantastic to work with... but I just can't imagine in what
real-world cases this would be useful.

Greetings !

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] strip out repeated ocurrence of a string

2010-01-26 Thread Camilo Sperberg

 a certain string can contain the following information:

 $string =
 'hi{value1;value2}bye{value1;value3}hi{value1;value4}hi{value1;value2}bye{value1;value2}';

 What I want is to be able to get this result:

 $string =
 'hi{value1;value2}bye{value1;value3}hi{value1;value4}bye{value1;value2}';

 (the order of appearance doesn't matter)


 Assuming the duplicate segments are identical.
 I'd use explode() and convert the string to an array. Use } for the
 delimiter.
 Then use array_unique()
 And then use implode() to restore the string.


Really nice solution indeed :D I didn't know array_unique() (well, that's
not entirely true, I had read about it once or twice, but didn't remembered
it).

Anyway, I remembered after I sended the mail that the order DO matter, but
that is just reversing an array :)
Just for the record, the applied code is:

$string =
implode('}',array_reverse(array_unique(array_reverse(explode('}',$string);

First, an explode of the string to create an array, than I reverse it so
that the last ocurrence of the repeated part will always be last, after that
I apply array_unique, de-reverse it and implode it all back together as a
string.

Result?
input:
hi{value1;value2}bye{value1;value3}hi{value1;value4}hi{value1;value2}bye{value1;value2}

output:
bye{value1;value3}hi{value1;value4}hi{value1;value2}bye{value1;value2}


Thank you very much !


@Ashley: It must be done in PHP, because it should run in any environment.
But thanks anyway, any help is apreciated: you just saw that there was a
much easier way than trying to use regular expressions or str_replace when
using arrays is considerably faster (especially because the $string won't be
a few bytes, it could range from ~5 bytes up to ~300+ KiB).

Greetings!

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] MySQL ID -- what happens when you run out of range?

2010-01-25 Thread Camilo Sperberg
On Mon, Jan 25, 2010 at 17:15, Parham Doustdar parha...@gmail.com wrote:

 Hello there,
 A friend called me today and was wondering what happens if the ID colomn of
 an MYSQL database, set to autoinc reaches the int limit. Will it return and
 begin choosing the ID's that have been deleted, or... what?
 Thanks!



from what I know, MySQL will convert that number into a negative number,
which would be invalid for an auto-increment field (auto-increment ==
unsigned). That would raise an error ;)

Greetings :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] MySQL ID -- what happens when you run out of range?

2010-01-25 Thread Camilo Sperberg
On Mon, Jan 25, 2010 at 18:51, Joseph Thayne webad...@thaynefam.org wrote:

  That is incorrect.  What will happen is as follows:

 1.  The value will be incremented by 1 causing the value to be greater than
 the maximum integer allowed.
 2.  MySQL will see this as a problem and truncate it to the closest
 value.
 3.  MySQL will then try and insert the new row with the updated id.
 4.  MySQL will find that the id already exists, and will return a duplicate
 ID error.

 If you want to verify what occurs, create a table with a tinyint value for
 the id and autoincrement it.


you're absolutely right ! sorry, my bad xD
MySQL does indeed truncate the value to the closest one... I had that
problem once xD (field was tinyint, but signed, which means max value for
that row was 127 instead of 255 which was what I needed, when I tried to
insert any value above 127 it was automaticly truncated to 127).




 It is correct also, that you cannot use negative numbers for the
 autoincrement field.


 Camilo Sperberg wrote:

 On Mon, Jan 25, 2010 at 17:15, Parham Doustdar parha...@gmail.com 
 parha...@gmail.com wrote:



  Hello there,
 A friend called me today and was wondering what happens if the ID colomn of
 an MYSQL database, set to autoinc reaches the int limit. Will it return and
 begin choosing the ID's that have been deleted, or... what?
 Thanks!





  from what I know, MySQL will convert that number into a negative number,
 which would be invalid for an auto-increment field (auto-increment ==
 unsigned). That would raise an error ;)

 Greetings :)






-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Php-cli, scripts freeze on exit

2010-01-25 Thread Camilo Sperberg
On Sun, Jan 24, 2010 at 16:16, David W. Allor da...@artisanpath.com wrote:

 Hi!

 I'm using php-cli 5.3.1.

 When I run php from the command line, the script does not return me to
 the command prompt when exited. The script always completes, but it has
 to be killed to release it's resources.

 I've created a little working example:


 #!/usr/bin/php
 ?
 echo 'hellu';
 exit(0);
 ?


 I execute the script by running ./test.php

 The script outputs hellu and then stops. It does not return to the
 command prompt. The only way back is to kill the script.

 This problem does not occur on my remote server, only on my home
 environment. I have home-network maintenance scripts that execute other
 scripts. If the executed script doesn't exit, the main scripts don't
 continue.

 I did a trace, and it turns out that the script is stopping on a futex
 wait.


do you have ubuntu home? Does other programs freez?

I had the same problem with ubuntu once... but rather than fixing it, I
decided to install fedora xD
It has something to do with multithreading, but i'm no expert in that. Some
suggest deactivating Assistive Technologies:
http://ubuntuforums.org/showthread.php?p=6144521

Greetings ;)




 Thanks,
 David W. Allor




-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


[PHP] strip out repeated ocurrence of a string

2010-01-25 Thread Camilo Sperberg
Hello list :)

I have this problem, a certain string can contain the following information:


$string = '
hi{value1;value2}
bye{value1;value3}
hi{value1;value4}
hi{value1;value2}
bye{value1;value2}
';

What I want is to be able to get this result:

$string = '
hi{value1;value2}
bye{value1;value3}
hi{value1;value4}
bye{value1;value2}
';

(the order of appearance doesn't matter)
Is it even possible to do this with regular expresions? Or should I first
look if there is some kind of match and then apply an
str_replace($match,'',$string) and add the $match again?

Greetings !

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] 304 Not Modified header not working within a class

2010-01-23 Thread Camilo Sperberg
Problem solved!!!

Everything was working ok with PHP. My class was working ok. The engineering
and logic behind PHP was working. So... what was the problem? Apache...
well, it wasn't a problem, but a misconfiguration or better said, a
mis-optimization.
In my first message, I stated: (quote)

 there is no way I can send a 304 Not Modified header, when the data is
 *over* ~100 bytes.


After 8 hours of working with this problem (which included sniffering and a
lot of workarounds), and while I was smoking my final cigarrette before
going to bed, I remembered that some time ago (well, some time like 2 years
ago xD), I had enabled mod_disk_cache, with the following configuration:
IfModule mod_disk_cache.c
  CacheRoot /tmp/apachecache/
  CacheEnable disk /
  CacheDirLength 1
  CacheDirLevels 5
  CacheMaxFileSize 128000
  *CacheMinFileSize 100*
/IfModule

I commented that part, restarted Apache and bingo Instantly I had an 304
header.
What do I think the problem was? Whenever Apache received a request, it
handled it directly from _his_ cache and simply omitted what PHP was telling
him to do. The weird thing was that the class entered the 304 header part,
but Apache always ended up sending an 200 OK header and then the CSS. In
first place it shouldn't have sended the CSS because when I entered the 304
part, it should have died. It simply couldn't send any other output. (And
that was why I sniffered, if it shouldn't send the CSS; he must have been
send some kind of error, but my surprise was really big when I saw that the
raw data was just plain CSS, no other data was present).
Why was Apache then sending a 304 whenever the data was under the 100 byte
limit? Because he didn't have it in his cache and was obeying what PHP told
him to do. (This configuration created a cache whenever the file size is
between the 100 and 128000 bytes).

Anyway... now I will be publishing the class soon on phpclasses.org under
the BSD license. I'll work now on documentation and code cleanup but
whenever it is ready I will leave the link in this same list (if it is
allowed) xD

Greetings, a lot of thanks to Richard for his code and Rene for his
suggestion to take a look at Apache and good night :P (Despite being 7AM xD)


On Wed, Jan 20, 2010 at 21:16, Camilo Sperberg csperb...@unreal4u.comwrote:



 On Wed, Jan 20, 2010 at 04:34, richard gray r...@richgray.com wrote:


 Camilo Sperberg wrote:

 Hi list, my first message here :)

 To the point: I'm programming a class that takes several CSS files,
 parses,
 compresses and saves into a cache file. However, I would like to go a
 step
 further and also use the browser cache, handling the 304 and 200 header
 types myself.

 Now, what is the problem? If I do it within a function, there is
 absolutely
 no problem, everything works like a charm. However, when I implement that
 same concept into my class, there is no way I can send a 304 Not Modified
 header, when the data is *over* ~100 bytes.



 Hi Camilo

 For what it is worth I have implemented cacheing in a class and for me the
 304 not modified header gets sent fine ... some example headers output is
 below together with the relevant code snippet..

 // See if client sent a page modified header to see if we can
 // just send a not modified header instead
 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) 
 $_SERVER['HTTP_IF_MODIFIED_SINCE'] == self::$_gmmodtime) {

   header('HTTP/1.1 304 Not Modified');
   return null;
 }

 if (isset($_SERVER['HTTP_IF_NONE_MATCH']) 
 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == self::$_etag) {

   header('HTTP/1.1 304 Not Modified');
   return null;
 }


 HTTP/1.x 304 Not Modified
 Date: Wed, 20 Jan 2010 07:21:32 GMT
 Server: Apache/2.2.11 (Ubuntu)
 Connection: Keep-Alive
 Keep-Alive: timeout=5, max=1000
 Etag: 444fbd9951f540ec1b6928db864c10dc
 Expires: Sun, 24 Jan 2010 06:16:06 GMT
 Cache-Control: public, must-revalidate
 Vary: Accept-Encoding

 I hope it helps..

 Regards
 Rich


 I'll try this (and some other things I recently thought about) when I get
 back home on friday :) I'll keep you updated.

 Thanks!


 --
 Mailed by:
 UnReAl4U - unreal4u
 ICQ #: 54472056
 www1: http://www.chw.net/
 www2: http://unreal4u.com/




-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] 304 Not Modified header not working within a class

2010-01-20 Thread Camilo Sperberg
On Wed, Jan 20, 2010 at 04:34, richard gray r...@richgray.com wrote:


 Camilo Sperberg wrote:

 Hi list, my first message here :)

 To the point: I'm programming a class that takes several CSS files,
 parses,
 compresses and saves into a cache file. However, I would like to go a step
 further and also use the browser cache, handling the 304 and 200 header
 types myself.

 Now, what is the problem? If I do it within a function, there is
 absolutely
 no problem, everything works like a charm. However, when I implement that
 same concept into my class, there is no way I can send a 304 Not Modified
 header, when the data is *over* ~100 bytes.



 Hi Camilo

 For what it is worth I have implemented cacheing in a class and for me the
 304 not modified header gets sent fine ... some example headers output is
 below together with the relevant code snippet..

 // See if client sent a page modified header to see if we can
 // just send a not modified header instead
 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) 
 $_SERVER['HTTP_IF_MODIFIED_SINCE'] == self::$_gmmodtime) {

   header('HTTP/1.1 304 Not Modified');
   return null;
 }

 if (isset($_SERVER['HTTP_IF_NONE_MATCH']) 
 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == self::$_etag) {

   header('HTTP/1.1 304 Not Modified');
   return null;
 }


 HTTP/1.x 304 Not Modified
 Date: Wed, 20 Jan 2010 07:21:32 GMT
 Server: Apache/2.2.11 (Ubuntu)
 Connection: Keep-Alive
 Keep-Alive: timeout=5, max=1000
 Etag: 444fbd9951f540ec1b6928db864c10dc
 Expires: Sun, 24 Jan 2010 06:16:06 GMT
 Cache-Control: public, must-revalidate
 Vary: Accept-Encoding

 I hope it helps..

 Regards
 Rich


I'll try this (and some other things I recently thought about) when I get
back home on friday :) I'll keep you updated.

Thanks!

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] 304 Not Modified header not working within a class

2010-01-19 Thread Camilo Sperberg
On Wed, Jan 20, 2010 at 02:33, Rene Veerman rene7...@gmail.com wrote:

 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) AND
 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified) {


 shouldn't that be

 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) = $last_modified)

 ?


Now that I think about it... yes; but I send the last modified header anyway
the first time (when $_SERVER['HTTP_IF_MODIFIED_SINCE'] == null):
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$last_modified).' GMT');

So if it isn't exactly equal, then the browser cache simply doesn't have the
latest version. It is impossible anyway that the browser can have a newer
version that doesn't previously exist on the server.
My best guess is that it doesn't affect the process: when I implement that
code in my class, it enters that part (meaning all the comparisons are ok)
but afterwards it keeps sending an 200 OK header when I explicitly tell
Apache to send the 304 Not Modified one.

Greetings and thanks for sharing :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


[PHP] 304 Not Modified header not working within a class

2010-01-16 Thread Camilo Sperberg
Hi list, my first message here :)

To the point: I'm programming a class that takes several CSS files, parses,
compresses and saves into a cache file. However, I would like to go a step
further and also use the browser cache, handling the 304 and 200 header
types myself.

Now, what is the problem? If I do it within a function, there is absolutely
no problem, everything works like a charm. However, when I implement that
same concept into my class, there is no way I can send a 304 Not Modified
header, when the data is *over* ~100 bytes.

What is funnier is that it enters the 304 function within the class, but
apparently it doesn't respect that and ends sending a 200 OK header anyway.
Let's take a look at the code:

This is a simple test scenario implemented within a little file just to
proof and make sure it is working before I adapt the code in the class.
Everything is ok here:

define('TIME_BROWSER_CACHE','3600');
$last_modified = filemtime('blabla.css');

if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) AND
strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified) {
  header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified',TRUE,304);
  header('Pragma: public');
  header('Last-Modified: '.gmdate('D, d M Y H:i:s',$last_modified).' GMT');
  header('Cache-Control: max-age='.TIME_BROWSER_CACHE.', must-revalidate,
public');
  header('Expires: '.gmdate('D, d M Y H:i:s',time() + TIME_BROWSER_CACHE).'
GMT');
  die();
}
header('Content-type: text/css; charset=UTF-8');
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$last_modified).' GMT');
header('Cache-Control: max-age='.TIME_BROWSER_CACHE.', must-revalidate,
public');
header('Expires: '.gmdate('D, d M Y H:i:s',time() + TIME_BROWSER_CACHE).'
GMT');

Now the class (simplified):

  public function printme($method = 'file') {
if($this-qCSS  0 AND ($method == 'file' OR $method = 'inline')) {
  if ($method == 'file') {
$last_modified = filemtime(CACHE_LOCATION);
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) AND
strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified AND
$this-valid_cache()) {
  // $this-valid_cache() determines if the internal CSS cache is
still valid. If it is, it returns TRUE, else FALSE
  header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified', TRUE,
304);
  // also tried sending header('HTTP/1.1 304 Not Modified'); but
that didn't do the trick
  header('Pragma: public'); // Useless? Maybe, but the function
works with or without it.
  header('Last-Modified: '.gmdate('D, d M Y H:i:s',$last_modified).'
GMT'); // Always good to send this too.
  header('Cache-Control: max-age='.TIME_BROWSER_CACHE); // idem
  header('Expires: '.gmdate('D, d M Y H:i:s',time() +
TIME_BROWSER_CACHE).' GMT'); // idem
  $fp = fopen('cache/hi.txt','a'); // Just to check stuff
  fwrite($fp,'header 304 sended, let\'s die'.\n); // It logs this
without problem, which means it really enters this function when needed.
  fclose($fp);
  die(); // Terminate script execution or else it would continue to
the bottom, which isn't necessary.
}
header('Content-type: text/css; charset='.CHARSET); // From here on,
it applies only if we need to send the CSS.
if (USE_BROWSER_CACHE) { // Constant [TRUE|FALSE] which defines
whether to use the browser cache or not.
  header('Pragma: public');
  header('Last-Modified: '.gmdate('D, d M Y H:i:s',$last_modified).'
GMT');
  header('Cache-Control: max-age='.TIME_BROWSER_CACHE);
  header('Expires: '.gmdate('D, d M Y H:i:s',time() +
TIME_BROWSER_CACHE).' GMT');
}
// Rest of the function: get the CSS and echo it, within an
ob_start('ob_gzhandler');
()
$content_length = filesize(CACHE_LOCATION);
if (extension_loaded('zlib')) $content_length = ob_get_length();
header('Content-Length: '.$content_length); // Necesary if we don't
want to send the CSS in chunks.
if (extension_loaded('zlib')) ob_end_flush();

Other useful information:
- Code #1 returns an 304 when it is needed, even when the CSS size is over
50kb. (Haven't test any CSS over that size yet)
- Code #2 goes into the 304 part but doesn't send the 304, unless the total
CSS size is under 100 bytes.
- Tried also with ETags, didn't worked either.
- Tried increasing or decreasing TIME_BROWSER_CACHE, didn't worked.
- Tried with/without Pragma header, Last-Modified header, Cache-Control
header, Expires header, all the 16 posibilities. None of them worked.
- Tried with getallheaders() and making the proper changes.
- Tried with/without ob_gzhandler.
- Tried with/without ob_start().
- Tried with all options on/off within Last-Modified header and
Cache-Control header (must-revalidate, public, etc). None of them worked.
- Tried searching on Google, reading the comments on php.net and searching
within this list. Nothing like this came up.
- I've been