php-general Digest 12 Nov 2012 23:24:50 -0000 Issue 8037
Topics (messages 319687 through 319700):
serialize() casts numeric string keys to integers
319687 by: eyal.t
319692 by: Adam Richardson
Re: Date comparison going wrong, wrong, wrong
319688 by: marco.behnke.biz
319689 by: Duken Marga
Re: memory allocation error
319690 by: Carol Peck
319691 by: Jim Lucas
319693 by: Carol Peck
319694 by: Carol Peck
319695 by: James
319696 by: James
319697 by: Jim Lucas
319698 by: Jim Lucas
319699 by: Matijn Woudt
319700 by: Carol Peck
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
Hi all,
Was wondering whether the fact that serialize() casts numeric string
keys to integers, is a bug, intended behaviour, or just something that
is minor enough not to have bothered anyone yet?
<?php
$arr1 = array('1'=>'string key'); // '1' will be casted to 1
$arr2 = array(1=>'integer key');
$arr1_uns = unserialize(serialize($arr1)) ;
$arr2_uns = unserialize(serialize($arr2)) ;
var_dump($arr1_uns, $arr2_uns);
==============================
array(1) {
[1]=>
string(10) "string key"
}
array(1) {
[1]=>
string(11) "integer key"
}
--- End Message ---
--- Begin Message ---
On Mon, Nov 12, 2012 at 2:18 AM, eyal.t <eya...@zend.com> wrote:
> Hi all,
>
> Was wondering whether the fact that serialize() casts numeric string keys
> to integers, is a bug, intended behaviour, or just something that is minor
> enough not to have bothered anyone yet?
>
This behavior is consistent with the standard key casts for arrays:
http://php.net/manual/en/language.types.array.php
Try dumping the array before the serialize operations.
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
--- End Message ---
--- Begin Message ---
"Terry Ally (Gmail)" <terrya...@gmail.com> hat am 11. November 2012 um 19:30
geschrieben:
> Hi all,
>
> I am having a problem with comparing time. I am using the following:
>
> $todaydate = date("D, M jS, Y g:i:s a");
> $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));
>
> if ($todaydate > $showenddate):
Read about http://de1.php.net/manual/en/datetime.diff.php
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> The problem that I am encountering is that PHP is rendering the reverse of
> the equation. For example:
>
> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
> the message that I am getting is *the show has ended* which is wrong. A
> test example is at http://www.lakesidesurrey.co.uk/test.php.
>
> You can also me what I am doing wrong?
>
> Thanks
> Terry
--
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
--- End Message ---
--- Begin Message ---
Try this:
$todaydate = strtotime(date("D, M jS, Y g:i:s a"));
$showenddate = strtotime(date("D, M jS, Y g:i:s a",
strtotime($showsRecord['end_date'])));
if ($todaydate < $showenddate):
echo "The date of the show has not yet arrived";
else:
echo "The show has ended";
endif;
You must convert both $todaydate and $showendate with strtotime() function,
then you can compare them.
On Mon, Nov 12, 2012 at 1:30 AM, Terry Ally (Gmail) <terrya...@gmail.com>wrote:
> Hi all,
>
> I am having a problem with comparing time. I am using the following:
>
> $todaydate = date("D, M jS, Y g:i:s a");
> $showenddate = date("D, M jS, Y g:i:s a",
> strtotime($showsRecord['end_date']));
>
> if ($todaydate > $showenddate):
> echo "The date of the show has not yet arrived";
> else:
> echo "The show has ended";
> endif;
>
> The problem that I am encountering is that PHP is rendering the reverse of
> the equation. For example:
>
> If today's date is *11 Nov 2012* and the show's end date is *18 Nov 2012*,
> the message that I am getting is *the show has ended* which is wrong. A
> test example is at http://www.lakesidesurrey.co.uk/test.php.
>
> You can also me what I am doing wrong?
>
> Thanks
> Terry
>
--
Duken Marga
--- End Message ---
--- Begin Message ---
Sebastian,
Yes, I do , but this particular error never gets into my custom handler.
I have also set it so that fatal errors fall through, and that doesn't
seem to make any difference (again, probably because it never gets there).
Carol
On 11/11/2012 11:16 AM, Sebastian Krebs wrote:
Hi,
Do you use a custom error handler?
Regards,
Sebastian
2012/11/11 Carol Peck<carolap...@gmail.com>
Hi all,
I've been chasing around a memory allocation error for some time and can't
figure it out. It is somewhat random - I can run the script 3 times and
then it will happen, or sometimes the first time.
It happens at the very end of a script, actually after the script has
finished running. I will see the following after the closing</html> tag:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate 494142432 bytes) in Unknown on line 0
Just previous to this my mem usage is 3772104
The script itself does some database work (deletes, inserts, selects) but
nothing very heavy and writes out an XML file. I use adodb 5.18, the
server is PHP 5.3.18 (this was updated recently) and it is a VPS on
inmotionhosting.com.
As you can see, the memory limit is 256M so it's really high and I never
see that I'm using more than 4M. The error doesn't fall through my error
class - I'm assuming that's because it is happening after the script is
complete.
I am completely out of ideas on how to trap it or figure it out.
Any ideas would be appreciated!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On 11/11/2012 08:45 AM, Carol Peck wrote:
Hi all,
I've been chasing around a memory allocation error for some time and
can't figure it out. It is somewhat random - I can run the script 3
times and then it will happen, or sometimes the first time.
It happens at the very end of a script, actually after the script has
finished running. I will see the following after the closing </html> tag:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate 494142432 bytes) in Unknown on line 0
Just previous to this my mem usage is 3772104
The script itself does some database work (deletes, inserts, selects)
but nothing very heavy and writes out an XML file. I use adodb 5.18, the
server is PHP 5.3.18 (this was updated recently) and it is a VPS on
inmotionhosting.com.
As you can see, the memory limit is 256M so it's really high and I never
see that I'm using more than 4M. The error doesn't fall through my error
class - I'm assuming that's because it is happening after the script is
complete.
I am completely out of ideas on how to trap it or figure it out.
Any ideas would be appreciated!
Try adding exit or die at the end of what you know is the end of your
scripts. See if the problem continues. Maybe at the very end of your
customer error handler.
If the problem stops showing up, you might want to look at your PHP
config to see if anything is setup in the "auto_append_file" section.
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--- End Message ---
--- Begin Message ---
Jim,
Thanks for your idea - using die prevents it from coming up. As I
mentioned, it is rather random so sometimes hard to verify.
My auto_prepend and auto_append have no value in php.ini. I'm
wondering why you suggested that?
Best,
Carol
On 11/12/2012 8:09 AM, Jim Lucas wrote:
On 11/11/2012 08:45 AM, Carol Peck wrote:
Hi all,
I've been chasing around a memory allocation error for some time and
can't figure it out. It is somewhat random - I can run the script 3
times and then it will happen, or sometimes the first time.
It happens at the very end of a script, actually after the script has
finished running. I will see the following after the closing </html>
tag:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate 494142432 bytes) in Unknown on line 0
Just previous to this my mem usage is 3772104
The script itself does some database work (deletes, inserts, selects)
but nothing very heavy and writes out an XML file. I use adodb 5.18, the
server is PHP 5.3.18 (this was updated recently) and it is a VPS on
inmotionhosting.com.
As you can see, the memory limit is 256M so it's really high and I never
see that I'm using more than 4M. The error doesn't fall through my error
class - I'm assuming that's because it is happening after the script is
complete.
I am completely out of ideas on how to trap it or figure it out.
Any ideas would be appreciated!
Try adding exit or die at the end of what you know is the end of your
scripts. See if the problem continues. Maybe at the very end of your
customer error handler.
If the problem stops showing up, you might want to look at your PHP
config to see if anything is setup in the "auto_append_file" section.
--- End Message ---
--- Begin Message ---
Jim,
I just found that the die didn't fix it after all - just ran into it again.
So still looking for ideas!
thanks,
Carol
On 11/12/2012 8:09 AM, Jim Lucas wrote:
On 11/11/2012 08:45 AM, Carol Peck wrote:
Hi all,
I've been chasing around a memory allocation error for some time and
can't figure it out. It is somewhat random - I can run the script 3
times and then it will happen, or sometimes the first time.
It happens at the very end of a script, actually after the script has
finished running. I will see the following after the closing </html>
tag:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate 494142432 bytes) in Unknown on line 0
Just previous to this my mem usage is 3772104
The script itself does some database work (deletes, inserts, selects)
but nothing very heavy and writes out an XML file. I use adodb 5.18, the
server is PHP 5.3.18 (this was updated recently) and it is a VPS on
inmotionhosting.com.
As you can see, the memory limit is 256M so it's really high and I never
see that I'm using more than 4M. The error doesn't fall through my error
class - I'm assuming that's because it is happening after the script is
complete.
I am completely out of ideas on how to trap it or figure it out.
Any ideas would be appreciated!
Try adding exit or die at the end of what you know is the end of your
scripts. See if the problem continues. Maybe at the very end of your
customer error handler.
If the problem stops showing up, you might want to look at your PHP
config to see if anything is setup in the "auto_append_file" section.
--- End Message ---
--- Begin Message ---
This could be an issue with the library you're using, adodb, I'd check to see
if it has any debugging options to enable. I'm not familiar with it at all but
that may be helpful. I'd also check out adodbs bug tracker, if one exists.
Another suggestion would be use a profiler, such as xdebug, I believe thats the
name.
Carol Peck <carolap...@gmail.com> wrote:
>Jim,
>I just found that the die didn't fix it after all - just ran into it
>again.
>So still looking for ideas!
>thanks,
>
>Carol
>
>On 11/12/2012 8:09 AM, Jim Lucas wrote:
>> On 11/11/2012 08:45 AM, Carol Peck wrote:
>>> Hi all,
>>> I've been chasing around a memory allocation error for some time and
>>> can't figure it out. It is somewhat random - I can run the script 3
>>> times and then it will happen, or sometimes the first time.
>>>
>>> It happens at the very end of a script, actually after the script
>has
>>> finished running. I will see the following after the closing </html>
>
>>> tag:
>>>
>>> Fatal error: Allowed memory size of 268435456 bytes exhausted (tried
>to
>>> allocate 494142432 bytes) in Unknown on line 0
>>>
>>> Just previous to this my mem usage is 3772104
>>>
>>>
>>> The script itself does some database work (deletes, inserts,
>selects)
>>> but nothing very heavy and writes out an XML file. I use adodb 5.18,
>the
>>> server is PHP 5.3.18 (this was updated recently) and it is a VPS on
>>> inmotionhosting.com.
>>>
>>> As you can see, the memory limit is 256M so it's really high and I
>never
>>> see that I'm using more than 4M. The error doesn't fall through my
>error
>>> class - I'm assuming that's because it is happening after the script
>is
>>> complete.
>>>
>>> I am completely out of ideas on how to trap it or figure it out.
>>> Any ideas would be appreciated!
>>>
>>>
>>>
>>>
>>
>> Try adding exit or die at the end of what you know is the end of your
>
>> scripts. See if the problem continues. Maybe at the very end of your
>
>> customer error handler.
>>
>> If the problem stops showing up, you might want to look at your PHP
>> config to see if anything is setup in the "auto_append_file" section.
>>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
--- End Message ---
--- Begin Message ---
>---- Original Message ----
>From: James <ja...@nixsecurity.org>
>To: "Carol Peck" <carolap...@gmail.com>, "Jim Lucas" <li...@cmsws.com>
>Cc: php-gene...@lists.php.net
>Sent: Mon, Nov 12, 2012, 12:53 PM
>Subject: Re: [PHP] memory allocation error
>
>This could be an issue with the library you're using, adodb, I'd check to see
>if it has any debugging options to enable. I'm not familiar with it at all but
>that may be helpful. I'd also check out adodbs bug tracker, if one exists.
>Another suggestion would be use a profiler, such as xdebug, I believe thats
>the name.
>
>Carol Peck <carolap...@gmail.com> wrote:
>
>>Jim,
>>I just found that the die didn't fix it after all - just ran into it
>>again.
>>So still looking for ideas!
>>thanks,
>>
>>Carol
>>
>>On 11/12/2012 8:09 AM, Jim Lucas wrote:
>>> On 11/11/2012 08:45 AM, Carol Peck wrote:
>>>> Hi all,
>>>> I've been chasing around a memory allocation error for some time and
>>>> can't figure it out. It is somewhat random - I can run the script 3
>>>> times and then it will happen, or sometimes the first time.
>>>>
>>>> It happens at the very end of a script, actually after the script
>>has
>>>> finished running. I will see the following after the closing </html>
>>
>>>> tag:
>>>>
>>>> Fatal error: Allowed memory size of 268435456 bytes exhausted (tried
>>to
>>>> allocate 494142432 bytes) in Unknown on line 0
>>>>
>>>> Just previous to this my mem usage is 3772104
>>>>
>>>>
>>>> The script itself does some database work (deletes, inserts,
>>selects)
>>>> but nothing very heavy and writes out an XML file. I use adodb 5.18,
>>the
>>>> server is PHP 5.3.18 (this was updated recently) and it is a VPS on
>>>> inmotionhosting.com.
>>>>
>>>> As you can see, the memory limit is 256M so it's really high and I
>>never
>>>> see that I'm using more than 4M. The error doesn't fall through my
>>error
>>>> class - I'm assuming that's because it is happening after the script
>>is
>>>> complete.
>>>>
>>>> I am completely out of ideas on how to trap it or figure it out.
>>>> Any ideas would be appreciated!
>>>>
>>>>
>>>>
>>>>
>>>
>>> Try adding exit or die at the end of what you know is the end of your
>>
>>> scripts. See if the problem continues. Maybe at the very end of your
>>
>>> customer error handler.
>>>
>>> If the problem stops showing up, you might want to look at your PHP
>>> config to see if anything is setup in the "auto_append_file" section.
>>>
>>
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>
>--
>Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Sorry for top posting.
--- End Message ---
--- Begin Message ---
On 11/12/2012 7:50 AM, Carol Peck wrote:
Jim,
Thanks for your idea - using die prevents it from coming up. As I
mentioned, it is rather random so sometimes hard to verify.
My auto_prepend and auto_append have no value in php.ini. I'm
wondering why you suggested that?
If something was injecting code using the auto_append param, then you
would not know about it, but it would still cause you issues. And by
issuing a die or exit at the end of the code would show if it was your
code or something running after all your script has completed.
Best,
Carol
On 11/12/2012 8:09 AM, Jim Lucas wrote:
On 11/11/2012 08:45 AM, Carol Peck wrote:
Hi all,
I've been chasing around a memory allocation error for some time and
can't figure it out. It is somewhat random - I can run the script 3
times and then it will happen, or sometimes the first time.
It happens at the very end of a script, actually after the script has
finished running. I will see the following after the closing </html>
tag:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to
allocate 494142432 bytes) in Unknown on line 0
Just previous to this my mem usage is 3772104
The script itself does some database work (deletes, inserts, selects)
but nothing very heavy and writes out an XML file. I use adodb 5.18, the
server is PHP 5.3.18 (this was updated recently) and it is a VPS on
inmotionhosting.com.
As you can see, the memory limit is 256M so it's really high and I never
see that I'm using more than 4M. The error doesn't fall through my error
class - I'm assuming that's because it is happening after the script is
complete.
I am completely out of ideas on how to trap it or figure it out.
Any ideas would be appreciated!
Try adding exit or die at the end of what you know is the end of your
scripts. See if the problem continues. Maybe at the very end of your
customer error handler.
If the problem stops showing up, you might want to look at your PHP
config to see if anything is setup in the "auto_append_file" section.
--- End Message ---
--- Begin Message ---
On 11/12/2012 8:54 AM, Carol Peck wrote:
Jim,
I just found that the die didn't fix it after all - just ran into it again.
So still looking for ideas!
thanks,
Carol
Then it must be something in either your code or the way PHP is doing
some garbage collection with the libs you are using.
--- End Message ---
--- Begin Message ---
On Mon, Nov 12, 2012 at 3:17 PM, Carol Peck <carolap...@gmail.com> wrote:
> Sebastian,
> Yes, I do , but this particular error never gets into my custom handler.
> I have also set it so that fatal errors fall through, and that doesn't
> seem to make any difference (again, probably because it never gets there).
>
> Carol
>
>
Can you post the code of the error handler? I guess the bug is there. Bugs
like these are mostly because of recursion errors or something. (Don't know
if it's possible, but an error inside the error handler?)
Fatal errors will btw always fall through, you can't catch fatal errors.
You should, for testing, turn off your custom error handler and see what it
does.
- Matijn
Ps. Please bottom-post on this mailing list.
--- End Message ---
--- Begin Message ---
On 11/12/2012 11:51 AM, Matijn Woudt wrote:
On Mon, Nov 12, 2012 at 3:17 PM, Carol Peck <carolap...@gmail.com
<mailto:carolap...@gmail.com>> wrote:
Sebastian,
Yes, I do , but this particular error never gets into my custom
handler.
I have also set it so that fatal errors fall through, and that
doesn't seem to make any difference (again, probably because it
never gets there).
Carol
Can you post the code of the error handler? I guess the bug is there.
Bugs like these are mostly because of recursion errors or something.
(Don't know if it's possible, but an error inside the error handler?)
Fatal errors will btw always fall through, you can't catch fatal
errors. You should, for testing, turn off your custom error handler
and see what it does.
- Matijn
Ps. Please bottom-post on this mailing list.
Here is the error class (I hope I"m posting the code the right way). I
will turn this off for a while.
It's main purpose is to format the message before logging. I do know
that things are getting logged properly.
Thanks again.
<?php
/**
* Error Handler class
*
* Handles E_USER_ERROR, E_USER_WARNING, E_WARNING, E_USER_NOTICE,
* and E_NOTICE errors.
*/
class ErrorHandler
{
/**
protected $_noticeLog = '/tmp/notice.log';
protected $_errorLog = '/tmp/error_handler.log';
public function __construct($message, $filename, $linenum, $vars)
{
$this->message = $message;
$this->filename = $filename;
$this->line = $linenum;
$this->vars = $vars;
}
public static function handle($errno, $errmsg, $filename, $line, $vars)
{
$self = new self($errmsg, $filename, $line, $vars);
switch ($errno) {
case E_USER_ERROR:
return $self->handleError();
case E_USER_WARNING:
case E_WARNING:
return $self->handleWarning();
case E_USER_NOTICE:
case E_NOTICE:
return $self->handleNotice();
default:
// Returning false tells PHP to revert control to the
// default error handler
return false;
}
}
public function handleError()
{
// Get backtrace
ob_start();
debug_print_backtrace();
$backtrace = ob_get_flush();
$body =<<<EOT
A fatal error occured in the application:
Message: {$this->message}
File: {$this->filename}
Line: {$this->line}
Backtrace:
{$backtrace}
EOT;
// Use PHP's error_log() function to send an email
//error_log($body, 1, 'sysad...@example.com', "Fatal error
occurred\n");
error_log($body, 1, 'cp...@wyom.net', "Subject: Fatal error
occurred\n");
return error_log($body, 3, APP_PATH . $this->_errorLog);
exit(1); // non 0 exit status indicates script failure
}
/**
* Handle warnings
*
* Warnings indicate environmental errors; email sysadmin and
* continue
*
* @return boolean
*/
public function handleWarning()
{
$body =<<<EOT
An environmental error occured in the application, and may indicate a
potential larger issue:
Message: {$this->message}
File: {$this->filename}
Line: {$this->line}
EOT;
$body = date('[Y-m-d H:i:s] ') . $body . "\n";
return error_log($body,3, APP_PATH . $this->_errorLog);
}
/**
* Handle notices
*
* @return boolean
*/
public function handleNotice()
{
$body =<<<EOT
A NOTICE was raised with the following information:
Message: {$this->message}
File: {$this->filename}
Line: {$this->line}
EOT;
$body = date('[Y-m-d H:i:s] ') . $body . "\n";
return error_log($body, 3, APP_PATH . $this->_noticeLog);
}
}
/**
* Set ErrorHandler::handle() as default error handler
*/
set_error_handler(array('ErrorHandler', 'handle'));
--- End Message ---