[PHP] importNode issue

2010-01-25 Thread Michael A. Peters
I'm experiencing a slight problem with importNODE putting unwanted 
carriage returns in the the output.


Here's my function:

// syntax highlighting
include_once('Text/Highlighter.php');

function syntaxHighlight($dom,$lang,$code) {
   $hl = Text_Highlighter::factory($lang);
   $out = $hl-highlight($code);
   //die($out);
   $tmpDOM = new DOMDocument('1.0','UTF-8');
   $tmpDOM-loadXML($out);
   $foo = $tmpDOM-saveXML();
   //die($foo);

   $nodeList = $tmpDOM-getElementsByTagName('div');
   $impDIV = $nodeList-item(0);
   $returnDIV = $dom-importNode($impDIV,true);

   return $returnDIV;
   }

-=-

Here's my test:

$code  =?php . \n\n;
$code .=require_once('/path/to/something'); . \n;
$code .=function somefunc(\$myfoo,\$mybar) { . \n;
$code .=   \$myfoobar = \$myfoo . \$mybar; . \n;
$code .=   return \$myfoobar; . \n;
$code .=   } . \n;
$code .=? . \n;

$fooTest = syntaxHighlight($dom,'PHP',$code);

-=-

If I uncomment the die($out) - I get what I expect spit to the screen, 
view source shows code that will do what I want.


If instead I uncomment die($foo) - I also get what I expect spit to 
screen. view source shows code that will do what I want.


However, if the function is allowed to continue, the imported div has 
carriage returns between each and every /spanspan which of course 
completely breaks the browser display because they are inside a 
pre/pre node.


Anyone know why importNode does this and how to fix it?

The only (untried) solution I can think of is to replace each carriage 
return with a br / and every space with #160; and then replace the 
pre with a div class='monospace' or some such hackery before running 
loadXML() on it. But I would rather not do that.


php 5.2.12 built against libxml 2.6.26

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



Re: [PHP] importNode issue

2010-01-25 Thread Michael A. Peters

Michael A. Peters wrote:



The only (untried) solution I can think of is to replace each carriage 
return with a br / and every space with #160; and then replace the 
pre with a div class='monospace' or some such hackery before running 
loadXML() on it. But I would rather not do that.


Even that isn't really working but what I think I may be able to do, 
though it would be a PITA, is go through the list of nodes one by one 
and create identical nodes and append them to a node that isn't imported.


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



Re: [PHP] importNode issue

2010-01-25 Thread Jochem Maas
highlight_string() function might be an easier route?

Op 1/25/10 9:55 AM, Michael A. Peters schreef:
 I'm experiencing a slight problem with importNODE putting unwanted
 carriage returns in the the output.
 
 Here's my function:
 
 // syntax highlighting
 include_once('Text/Highlighter.php');
 
 function syntaxHighlight($dom,$lang,$code) {
$hl = Text_Highlighter::factory($lang);
$out = $hl-highlight($code);
//die($out);
$tmpDOM = new DOMDocument('1.0','UTF-8');
$tmpDOM-loadXML($out);
$foo = $tmpDOM-saveXML();
//die($foo);
 
$nodeList = $tmpDOM-getElementsByTagName('div');
$impDIV = $nodeList-item(0);
$returnDIV = $dom-importNode($impDIV,true);
 
return $returnDIV;
}
 
 -=-
 
 Here's my test:
 
 $code  =?php . \n\n;
 $code .=require_once('/path/to/something'); . \n;
 $code .=function somefunc(\$myfoo,\$mybar) { . \n;
 $code .=   \$myfoobar = \$myfoo . \$mybar; . \n;
 $code .=   return \$myfoobar; . \n;
 $code .=   } . \n;
 $code .=? . \n;
 
 $fooTest = syntaxHighlight($dom,'PHP',$code);
 
 -=-
 
 If I uncomment the die($out) - I get what I expect spit to the screen,
 view source shows code that will do what I want.
 
 If instead I uncomment die($foo) - I also get what I expect spit to
 screen. view source shows code that will do what I want.
 
 However, if the function is allowed to continue, the imported div has
 carriage returns between each and every /spanspan which of course
 completely breaks the browser display because they are inside a
 pre/pre node.
 
 Anyone know why importNode does this and how to fix it?
 
 The only (untried) solution I can think of is to replace each carriage
 return with a br / and every space with #160; and then replace the
 pre with a div class='monospace' or some such hackery before running
 loadXML() on it. But I would rather not do that.
 
 php 5.2.12 built against libxml 2.6.26
 


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



[PHP] How to change a filename for download (e.g. jpeg, pdf etc.)

2010-01-25 Thread SED
Hi,

Can anyone point me to tutorials on how to change a filename for each
download? My goal is to give the downloader a random name for a picture or a
document, so he will never know what the original filename is.

Regards,
Summi




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



Re: [PHP] How to change a filename for download (e.g. jpeg, pdf etc.)

2010-01-25 Thread Lester Caine

SED wrote:

Hi,

Can anyone point me to tutorials on how to change a filename for each
download? My goal is to give the downloader a random name for a picture or a
document, so he will never know what the original filename is.


http://uk.php.net/manual/en/function.tempnam.php any use ...

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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



Re: [PHP] importNode issue

2010-01-25 Thread Michael A. Peters

Jochem Maas wrote:

highlight_string() function might be an easier route?


If I only ever wanted to highlight php it might be.

I found a workaround, though I don't like it.

add

$dom-formatOutput = false;

to the function and it displays perfectly, though viewing the generated 
source isn't as nice (hence why I add it only when that function is called).


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



[PHP] Re: How to change a filename for download (e.g. jpeg, pdf etc.)

2010-01-25 Thread Richard
Hi,

 Can anyone point me to tutorials on how to change a filename for each
 download? My goal is to give the downloader a random name for a picture or a
 document, so he will never know what the original filename is.

Try adding a Content-Disposition header:

?php
   header('Content-disposition: attachment; filename=fname.ext');
?

--
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 23rd January)

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



Re: [PHP] How to change a filename for download (e.g. jpeg, pdf etc.)

2010-01-25 Thread Ashley Sheridan
On Mon, 2010-01-25 at 10:03 +, SED wrote:

 Hi,
 
 Can anyone point me to tutorials on how to change a filename for each
 download? My goal is to give the downloader a random name for a picture or a
 document, so he will never know what the original filename is.
 
 Regards,
 Summi
 
 
 
 


I save the file using the temp filename given to it by PHP during the
upload process. If that's not possible, then some sort of hash (MD5 for
example) of the original file name would suffice. Then, when the user
requests that file, they have to request it with a URL like
file.php?file=hashname

The added benefit of this is that you can verify the user is logged in
or not too. The only problem would be if you were serving media files,
as no plugins I know of send all the correct headers for the media file
request, so your browser would see it as an anonymous request.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Re: Enforce a constant in a class.

2010-01-25 Thread Pete Ford

Richard Quadling wrote:

2010/1/22 Pete Ford p...@justcroft.com:

IMHO, a constant is not the correct beastie in this case - if you want it to
be different depending on the implementation then it ain't a constant!

You should probably have protected static variables in the interface, and
use the implementation's constructor to set the implementation-specific
value (or override the default)

interface SetKillSwitch
{
   protected static $isSet = TRUE;
   protected static $notes;
   protected static $date = '2010-01-22T11:23:32+';
}

class KilledClass implements SetKillSwitch
{
   public function __construct()
   {
   self::$isSet = FALSE;
   self::$date = '2010-01-21T09:30:00+';
   self::$notes = Test;
   }
}

Cheers
Pete Ford


And of course, Fatal error: Interfaces may not include member variables.





Ooops, sorry :)

I tend to end up using abstract base classes rather than interfaces for 
that sort of reason...


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



Re: [PHP] How to change a filename for download (e.g. jpeg, pdf etc.)

2010-01-25 Thread Mourad Boufarguine
take a look at this :

http://www.phpclasses.org/browse/package/3220.html


On Mon, Jan 25, 2010 at 11:32 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 On Mon, 2010-01-25 at 10:03 +, SED wrote:

  Hi,
 
  Can anyone point me to tutorials on how to change a filename for each
  download? My goal is to give the downloader a random name for a picture
 or a
  document, so he will never know what the original filename is.
 
  Regards,
  Summi
 
 
 
 


 I save the file using the temp filename given to it by PHP during the
 upload process. If that's not possible, then some sort of hash (MD5 for
 example) of the original file name would suffice. Then, when the user
 requests that file, they have to request it with a URL like
 file.php?file=hashname

 The added benefit of this is that you can verify the user is logged in
 or not too. The only problem would be if you were serving media files,
 as no plugins I know of send all the correct headers for the media file
 request, so your browser would see it as an anonymous request.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





Re: [PHP] Re: Enforce a constant in a class.

2010-01-25 Thread Richard Quadling
2010/1/25 Pete Ford p...@justcroft.com:
 Richard Quadling wrote:

 2010/1/22 Pete Ford p...@justcroft.com:

 IMHO, a constant is not the correct beastie in this case - if you want it
 to
 be different depending on the implementation then it ain't a constant!

 You should probably have protected static variables in the interface, and
 use the implementation's constructor to set the implementation-specific
 value (or override the default)

 interface SetKillSwitch
 {
       protected static $isSet = TRUE;
       protected static $notes;
       protected static $date = '2010-01-22T11:23:32+';
 }

 class KilledClass implements SetKillSwitch
 {
       public function __construct()
       {
               self::$isSet = FALSE;
               self::$date = '2010-01-21T09:30:00+';
               self::$notes = Test;
       }
 }

 Cheers
 Pete Ford

 And of course, Fatal error: Interfaces may not include member variables.




 Ooops, sorry :)

 I tend to end up using abstract base classes rather than interfaces for that
 sort of reason...

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



Essentially I was starting with the idea that a subclass with constant
X _MUST_ have constant Y and Z. That's what I wanted to enforce.

But, finding that defined() was enough, I now realize that Y and Z are
_not_ mandatory, but they are constants. So simply ...

$KillSwitchNotes = defined(get_called_class() . '::KILL_SWITCH_NOTES') ?: Null;

is enough and now the whole _MUST_ is gone and is now optional.

Much better.


Thank you to everyone who chipped in. Old dog should really have known
that old trick!


-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



[PHP] Recursion issue with Zend_Soap_AutoDiscovery.

2010-01-25 Thread Richard Quadling
Hi.

I'm in the process of building a web service which incorporates the
ability for the server to inform the client that a particular call has
been superseded by another.

So, cut down (I've removed all the other details), ...

class ServiceDetails
{
/**
 * Superseded by
 *
 * Details of the replacement service that is now available.
 *
 * @var ServiceDetails
 */
public $SupersededBy = Null;
}

When I try to use Zend_Soap_AutoDiscover() against this class, I get ...

Infinite recursion, cannot nest 'ServiceDetails' into itsself. (sic)

There has to be recursion, as there could be many levels of
supersedence, each one providing the details of their own replacement.

The call to return the service details read the requested
services/class constants. If there is a superseded entry, it creates a
new request for service details on the new class (the recursion).

If the value is Null, then there is no recursion.



I'm using ...

new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');

as the strategy as the service has arrays of complex types in the output.



If I use @var string and then manually replace the type in the WSDL
file from ...

  xsd:element name=SupersededBy type=xsd:string /

to

  xsd:element name=SupersededBy type=tns:ServiceDetails /

and use wsdl2php against this, it all _SEEMS_ to work OK.

So. Is this my best option? Or is there a way to do this that I'm missing?


Any ideas really.


Is this even a bug in the Zend_Soap_AutoDiscover class?



Regards,

Richard Quadling.




-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



[PHP] Re: Recursion issue with Zend_Soap_AutoDiscovery.

2010-01-25 Thread Nathan Rixham
Richard Quadling wrote:
 Hi.
 
 I'm in the process of building a web service which incorporates the
 ability for the server to inform the client that a particular call has
 been superseded by another.
 
 So, cut down (I've removed all the other details), ...
 
 class ServiceDetails
   {
   /**
* Superseded by
*
* Details of the replacement service that is now available.
*
* @var ServiceDetails
*/
   public $SupersededBy = Null;
   }
 
 When I try to use Zend_Soap_AutoDiscover() against this class, I get ...
 
 Infinite recursion, cannot nest 'ServiceDetails' into itsself. (sic)
 
 There has to be recursion, as there could be many levels of
 supersedence, each one providing the details of their own replacement.
 
 The call to return the service details read the requested
 services/class constants. If there is a superseded entry, it creates a
 new request for service details on the new class (the recursion).
 
 If the value is Null, then there is no recursion.
 
 
 
 I'm using ...
 
 new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
 
 as the strategy as the service has arrays of complex types in the output.
 
 
 
 If I use @var string and then manually replace the type in the WSDL
 file from ...
 
   xsd:element name=SupersededBy type=xsd:string /
 
 to
 
   xsd:element name=SupersededBy type=tns:ServiceDetails /
 
 and use wsdl2php against this, it all _SEEMS_ to work OK.
 
 So. Is this my best option? Or is there a way to do this that I'm missing?
 
 
 Any ideas really.
 

http://wso2.org/projects/wsf/php ;)

helpful eh


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



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

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

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

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

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

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

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

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

Ravi






On Sun, Jan 24, 2010 at 9:39 AM, D. Dante Lorenso da...@lorenso.com wrote:
 shiplu wrote:

 On Sun, Jan 24, 2010 at 3:11 AM, D. Dante Lorenso da...@lorenso.com
 wrote:

 All,

 I'm loading millions of records into a backend PHP cli script that I
 need to build a hash index from to optimize key lookups for data that
 I'm importing into a MySQL database.  The problem is that storing this
 data in a PHP array is not very memory efficient and my millions of
 records are consuming about 4-6 GB of ram.


 What are you storing? An array of row objects??
 In that case storing only the row id is will reduce the memory.

 I am querying a MySQL database which contains 40 million records and mapping
 string columns to numeric ids.  You might consider it normalizing the data.

 Then, I am importing a new 40 million records and comparing the new values
 to the old values.  Where the value matches, I update records, but where
 they do not match, I insert new records, and finally I go back and delete
 old records.  So, the net result is that I have a database with 40 million
 records that I need to sync on a daily basis.

 If you are loading full row objects, it will take a lot of memory.
 But if you just load the row id values, it will significantly decrease
 the memory amount.

 For what I am trying to do, I just need to map a string value (32 bytes) to
 a bigint value (8 bytes) in a fast-lookup hash.

 Besides, You can load row ids in a chunk by chunk basis. if you have
 10 millions of rows to process. load 1 rows as a chunk. process
 them then load the next chunk.  This will significantly reduce memory
 usage.

 When importing the fresh 40 million records, I need to compare each record
 with 4 different indexes that will map the record to existing other records,
 or into a group_id that the record also belongs to.  My current solution
 uses a trigger in MySQL that will do the lookups inside MySQL, but this is
 extremely slow.  Pre-loading the mysql indexes into PHP ram and processing
 that was is thousands of times faster.

 I just need an efficient way to hold my hash tables in PHP ram.  PHP arrays
 are very fast, but like my original post says, they consume way too much
 ram.

 A good algorithm can solve your problem anytime. ;-)

 It takes about 5-10 minutes to build my hash indexes in PHP ram currently
 which makes up for the 10,000 x speedup on key lookups that I get later on.
  I just want to not use the whole 6 GB of ram to do this.   I need an
 efficient hashing API that supports something like:

        $value = (int) fasthash_get((string) $key);
        $exists = (bool) fasthash_exists((string) $key);
        fasthash_set((string) $key, (int) $value);

 Or ... it feels like a memcached api but where the data is stored locally
 instead of accessed via a network.  So this is how my search led me to what
 appears to be a dead lchash extension.

 -- Dante

 --
 D. Dante Lorenso
 da...@lorenso.com
 972-333-4139

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



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



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

2010-01-25 Thread Parham Doustdar
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! 



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



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

2010-01-25 Thread Nathan Rixham
Parham Doustdar 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?

you change it to bigint before that happens :)

for a more accurate answer ask on the mysql forum?

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



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

2010-01-25 Thread Joseph Thayne

It will continue to use the max number which of course will cause an error.

Joseph

Parham Doustdar 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! 




  


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



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

2010-01-25 Thread John Meyer

On 1/25/2010 1:19 PM, Nathan Rixham wrote:

Parham Doustdar 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?


you change it to bigint before that happens :)

for a more accurate answer ask on the mysql forum?



Or the e-mail list: my...@lists.mysql.com (though I understand the 
cross-pollination)



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



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

2010-01-25 Thread Robert Cummings

Parham Doustdar 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! 


Ask Slashdot... I believe they hit the limit one day (several actually) 
for comments :)


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] Cookies sessions

2010-01-25 Thread Nisse Engström
On Thu, 21 Jan 2010 08:43:58 +1100, clanc...@cybec.com.au wrote:

 When you are working with sessions, provided you start your program with 
 session_id(), you
 can then do anything you like with session variables at any point in your 
 program. In my
 original question I asked if there was a cookie equivalent. 

The HTTP spec allows cookies to be sent after the content,
in trailing headers, but it's not usable practically. Few
browsers support it, and PHP certainly doesn't. You'd have
to write a CGI to get away with it.

The only user agents I know of that support trailers are
the WC3 and WDG validators, and Opera(!).

Trailer test:
http://luden.se/http/test/trailer/
Some results:
http://browsershots.org/http://luden.se/http/test/trailer/?p=63


/Nisse

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



Re: [PHP] Cookies sessions

2010-01-25 Thread Ashley Sheridan
On Mon, 2010-01-25 at 22:13 +0100, Nisse Engström wrote:

 On Thu, 21 Jan 2010 08:43:58 +1100, clanc...@cybec.com.au wrote:
 
  When you are working with sessions, provided you start your program with 
  session_id(), you
  can then do anything you like with session variables at any point in your 
  program. In my
  original question I asked if there was a cookie equivalent. 
 
 The HTTP spec allows cookies to be sent after the content,
 in trailing headers, but it's not usable practically. Few
 browsers support it, and PHP certainly doesn't. You'd have
 to write a CGI to get away with it.
 
 The only user agents I know of that support trailers are
 the WC3 and WDG validators, and Opera(!).
 
 Trailer test:
 http://luden.se/http/test/trailer/
 Some results:
 http://browsershots.org/http://luden.se/http/test/trailer/?p=63
 
 
 /Nisse
 


I didn't even know that that was possible. I'm glad in a way that the
other browsers and PHP don't support it, as it would make a lot of
things more difficult if not impossible to accomplish!

Thanks,
Ash
http://www.ashleysheridan.co.uk




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 Ryan Sun
For such a large data set, they would split into several sub tables,
otherwise the performance will be horrible

On Mon, Jan 25, 2010 at 3:39 PM, Robert Cummings rob...@interjinn.comwrote:

 Parham Doustdar 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!


 Ask Slashdot... I believe they hit the limit one day (several actually) for
 comments :)

 Cheers,
 Rob.
 --
 http://www.interjinn.com
 Application and Templating Framework for PHP


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




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

2010-01-25 Thread Joseph Thayne

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.


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 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 :)

  


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] Cookies sessions

2010-01-25 Thread Nisse Engström
On Mon, 25 Jan 2010 21:26:05 +, Ashley Sheridan wrote:

 On Mon, 2010-01-25 at 22:13 +0100, Nisse Engström wrote:
 
 The HTTP spec allows cookies to be sent after the content,
 in trailing headers, but it's not usable practically. Few
 browsers support it, and PHP certainly doesn't. You'd have
 to write a CGI to get away with it.
 
 The only user agents I know of that support trailers are
 the WC3 and WDG validators, and Opera(!).

[...and one (and a half) of my own tools...]

 I didn't even know that that was possible. I'm glad in a way that the
 other browsers and PHP don't support it, as it would make a lot of
 things more difficult if not impossible to accomplish!

What do you have in mind?

It would certainly make Clancy's job easier. Imagine...

?php
header (Trailer: Cookie);
/* PHP takes notice! */

echo '!DOCTYPE HTML PUBLIC...and so on and so forth...';
setcookie (...);
echo 'pSome more stuff...';
?

* If the program exits before the headers have been sent
  (eg. output buffering), PHP sends the headers as usual,
  with Content-Length: and Set-Cookie:, but skips the
  Trailer:.
* If the headers have to be sent before the program has
  exited, PHP sends Content-Encoding: chunked and
  Trailer:, and buffers any further header() or
  setcookie() calls.
  When the program does exit, PHP sends all the buffered
  headers, and perhaps logs warnings for any headers that
  are not allowed in the trailers or has not been announced
  in the Trailer: header.

Ah, it could have worked. It would have been great fun
writing the code to do it. (Writing output filters that
switch between Content-Length and chunked, and HTTP
1.0 and 1.1 was interesting).

Actually, now that I think about it, I don't think I have
actually tested the above in PHP. I'd be very surprised
if it worked though. :-)


/Nisse

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



[PHP] Upload file on IE8

2010-01-25 Thread Ernie Kemp
 

Good Day,

 

I'm having an issue with IE8, when I go to load a file the
program is not filling the $_FILES['user_file']['type']  .

  When I display  echo  Start.$_FILES['pix']['type'].End;
in IE8 I get StartEnd with nothing in between.  I expected image/pjpeg.
 
On FireFox I get image/jpeg.
 
Any suggestions?
Thanks,
/Ernie
 

 

 

 

 

 



[PHP] Re: Enforce a constant in a class.

2010-01-25 Thread Colin Guthrie
'Twas brillig, and Richard Quadling at 22/01/10 11:33 did gyre and gimble:
 Hello,
 
 One of the aspects of an interface is to enforce a public view of a
 class (as I see it).
 
 Within PHP, interfaces are allowed to have constants, but you cannot
 override them in a class implementing that interface.
 
 This seems wrong.
 
 The interface shouldn't define the value, just like it doesn't define
 the content of the method, it only defines its existence and requires
 that a class implementing the interface accurately matches the
 interface.
 
 Is there a reason for this behaviour?
 
 
 
 _OR_
 
 How do I enforce the presence of a constant in a class?
 
 ?php
 interface SetKillSwitch {
   const KILL_SWITCH_SET = True;
 
   // Produces an error as no definition exists.
   // const KILL_SWITCH_NOTES;
 
   // Cannot override in any class implementing this interface.
   const KILL_SWITCH_DATE = '2010-01-22T11:23:32+';
 }
 
 class KilledClass implements SetKillSwitch {
   // Cannot override as defined in interface SetKillSwitch.
   // const KILL_SWITCH_DATE = '2010-01-22T11:23:32+';
 }
 ?
 
 I want to enforce that any class implementing SetKillSwitch also has a
 const KILL_SWITCH_DATE and a const KILL_SWITCH_NOTES.
 
 I have to use reflection to see if the constant exists and throw an
 exception when it doesn't.
 
 The interface should only say that x, y and z must exist, not the
 values of x, y and z.

Forgive the perhaps silly question but why are you requiring to use
constants here.

I appreciate the desire to use Reflection but why not just define a
method that must be implemented in the interface?

interface SetKillSwitch {
  public function getKillDate();
  public function getKillNotes();
}


By virtue of something impementing the interface, you know the methods
will exist.

If you want to make implmentation of classes easier, then define and
abstract class with an appropriate constructor and implementation:


abstract class SetKillSwitchAbstract {
  private $_killDate;
  private $_killNotes;
  protected function __construct($killDate, $killNotes)
  {
$this-_killDate = $killDate;
$this-_killNotes = $killNotes;
  }

  public function getKillDate()
  {
return $this-_killDate;
  }

  public function getKillNotes()
  {
return $this-_killNotes;
  }
}


You can either put your implements SetKillSwitch in this class or the
derived classes depending on other methods you want to provide in the
base class.


I don't see why constants specifically are needed here. Rather than
using reflection you can just use instanceof or similar to tell if a
given object implements the interface or simply use the interface name
as a type specifier on an argument to another function/method etc.


Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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



Re: [PHP] Upload file on IE8

2010-01-25 Thread Ashley Sheridan
On Mon, 2010-01-25 at 17:41 -0500, Ernie Kemp wrote:

 
 
 Good Day,
 
  
 
 I’m having an issue with IE8, when I go to load a file
 the program is not filling the $_FILES['user_file']['type']  .
 
 
   When I display  “echo  Start.$_FILES['pix']['type'].End;”  
 in IE8 I get “StartEnd” with nothing in between.  I expected “image/pjpeg.
  
 On FireFox I get “image/jpeg.
  
 Any suggestions?
 Thanks,
 /Ernie
  
 
 
  

What do the other $_FILES fields say? Are they populated correctly?

I wouldn't rely on anything sent from the browser. IE is known to send
the mime type that matches the extension, not the contents of the file,
and for .jpg images it sends a different mime to every other browser
anyway, so it's pretty unreliable.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] XAMPP PHP 4/5

2010-01-25 Thread Alberto García Gómez
There's a think that I don't understand and I really really need to know. Can 
XAMPP run PHP4 and PHP5 at th same time? How?

Saludos Fraternales
_
Atte.
Alberto García Gómez M:.M:.
Administrador de Redes/Webmaster
IPI Carlos Marx, Matanzas. Cuba.
0145-2887(30-33) ext 124


__ Información de ESET NOD32 Antivirus, versión de la base de firmas de 
virus 4805 (20100125) __

ESET NOD32 Antivirus ha comprobado este mensaje.

http://www.eset.com



Re: [PHP] Upload file on IE8

2010-01-25 Thread Eric Lee
On Tue, Jan 26, 2010 at 6:41 AM, Ernie Kemp ernie.k...@sympatico.ca wrote:

   Good Day,



 I’m having an issue with IE8, when I go to load a file the
 program is not filling the $_FILES['user_file']['type']  .

   When I display  “echo  Start.$_FILES['pix']['type'].End;”  
 in IE8 I get “StartEnd” with nothing in between.  I expected “image/pjpeg.



 On FireFox I get “image/jpeg.



 Any suggestions?

 Thanks,

 /Ernie



  I remember a setting from some elsewhere IE 8 was disable set file path
 location
 by default from the options dialog. Did you enabled this already ? If not,
 you may give it a shoot to see than !


 Hope this help


 Eric,
 Regards,









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

2010-01-25 Thread D. Dante Lorenso

J Ravi Menon wrote:

PHP does expose sys V shared-memory apis (shm_* functions):
http://us2.php.net/manual/en/book.sem.php



I will look into this.  I really need a key/value map, though and would 
rather not have to write my own on top of SHM.




If you already have apc installed, you could also try:
http://us2.php.net/manual/en/book.apc.php
APC also allows you to store user specific data too (it will be in a
shared memory).



I've looked into the apc_store and apc_fetch routines:
http://php.net/manual/en/function.apc-store.php
http://www.php.net/manual/en/function.apc-fetch.php
... but quickly ran out of memory for APC and though I figured out how 
to configure it to use more (adjust shared memory allotment), there were 
other problems.  I ran into issues with logs complaining about cache 
slamming and other known bugs with APC version 3.1.3p1.  Also, after 
several million values were stored, the APC storage began to slow down 
*dramatically*.  I wasn't certain if APC was using only RAM or was 
possibly also writing to disk.  Performance tanked so quickly that I set 
it aside as an option and moved on.




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



I will run more tests against MongoDB.  Initially I tried to use it to 
store everything.  If I only store my indexes, it might fare better. 
Certainly, though, running queries and updates against a remote server 
will always be slower than doing the lookups locally in ram.




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


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


-- Dante



On Sun, Jan 24, 2010 at 9:39 AM, D. Dante Lorenso da...@lorenso.com wrote:

shiplu wrote:

On Sun, Jan 24, 2010 at 3:11 AM, D. Dante Lorenso da...@lorenso.com
wrote:

All,

I'm loading millions of records into a backend PHP cli script that I
need to build a hash index from to optimize key lookups for data that
I'm importing into a MySQL database.  The problem is that storing this
data in a PHP array is not very memory efficient and my millions of
records are consuming about 4-6 GB of ram.


What are you storing? An array of row objects??
In that case storing only the row id is will reduce the memory.

I am querying a MySQL database which contains 40 million records and mapping
string columns to numeric ids.  You might consider it normalizing the data.

Then, I am importing a new 40 million records and comparing the new values
to the old values.  Where the value matches, I update records, but where
they do not match, I insert new records, and finally I go back and delete
old records.  So, the net result is that I have a database with 40 million
records that I need to sync on a daily basis.


If you are loading full row objects, it will take a lot of memory.
But if you just load the row id values, it will significantly decrease
the memory amount.

For what I am trying to do, I just need to map a string value (32 bytes) to
a bigint value (8 bytes) in a fast-lookup hash.


Besides, You can load row ids in a chunk by chunk basis. if you have
10 millions of rows to process. load 1 rows as a chunk. process
them then load the next chunk.  This will significantly reduce memory
usage.

When importing the fresh 40 million records, I need to compare each record
with 4 different indexes that will map the record to existing other records,
or into a group_id that the record also belongs to.  My current solution
uses a trigger in MySQL that will do the lookups inside MySQL, but this is
extremely slow.  Pre-loading the mysql indexes into PHP ram and processing
that was is thousands of times faster.

I just need an efficient way to hold my hash tables in PHP ram.  PHP arrays
are very fast, but like my original post says, they consume way too much
ram.


A good algorithm can solve your problem anytime. ;-)

It takes about 5-10 minutes to build my hash indexes in PHP ram currently
which makes up for the 10,000 x speedup on key lookups that I get later on.
 I just want to not use the whole 6 GB of ram to do this.   I need an
efficient hashing API that supports something like:

   $value = (int) fasthash_get((string) $key);
   $exists = (bool) fasthash_exists((string) $key);
   fasthash_set((string) $key, (int) $value);

Or 

Re: [PHP] Upload file on IE8

2010-01-25 Thread Ashley Sheridan
On Tue, 2010-01-26 at 07:33 +0800, Eric Lee wrote:

 On Tue, Jan 26, 2010 at 6:41 AM, Ernie Kemp ernie.k...@sympatico.ca wrote:
 
Good Day,
 
 
 
  I’m having an issue with IE8, when I go to load a file the
  program is not filling the $_FILES['user_file']['type']  .
 
When I display  “echo  Start.$_FILES['pix']['type'].End;” 
   in IE8 I get “StartEnd” with nothing in between.  I expected “image/pjpeg.
 
 
 
  On FireFox I get “image/jpeg.
 
 
 
  Any suggestions?
 
  Thanks,
 
  /Ernie
 
 
 
   I remember a setting from some elsewhere IE 8 was disable set file path
  location
  by default from the options dialog. Did you enabled this already ? If not,
  you may give it a shoot to see than !
 
 
  Hope this help
 
 
  Eric,
  Regards,
 
 
 
 
 
 
 


But you won't be able to guarantee every IE8 user will do this, so you
shouldn't develop the app in such a way that it needs to use the value
in the array. Also, as I've said, there isn't much point relying on this
value for any reason anyway, as it doesn't guarantee the file is
actually of that type.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] Upload file on IE8

2010-01-25 Thread Ernie Kemp
 

 

 

 

From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: January-25-10 5:53 PM
To: Ernie Kemp
Cc: 'PHP General List'
Subject: Re: [PHP] Upload file on IE8

 

On Mon, 2010-01-25 at 17:41 -0500, Ernie Kemp wrote:



 

Good Day,

 

I’m having an issue with IE8, when I go to load a file the 
program is not filling the $_FILES['user_file']['type']  .

 
  When I display  “echo  Start.$_FILES['pix']['type'].End;”  in 
IE8 I get “StartEnd” with nothing in between.  I expected “image/pjpeg.
 
On FireFox I get “image/jpeg.
 
Any suggestions?
Thanks,
/Ernie
 

 

What do the other $_FILES fields say? Are they populated correctly?

I wouldn't rely on anything sent from the browser. IE is known to send the mime 
type that matches the extension, not the contents of the file, and for .jpg 
images it sends a different mime to every other browser anyway, so it's pretty 
unreliable. 


Thanks,
Ash
http://www.ashleysheridan.co.uk





With IE8,

  Using $_FILES the array results for  ‘name’ has the name of the file but 
‘type’, ‘tmp_name’ and ‘size’ are blanks.

 I tried enabling the “file path location” in IE8 option but the results 
are the same for $_FILES. 

 


   Firefox works displays all the values in the $_FILES array.

There must be a better way. Suggestions?

Thanks,

/Ernie



RE: [PHP] Upload file on IE8

2010-01-25 Thread Ashley Sheridan
On Mon, 2010-01-25 at 19:21 -0500, Ernie Kemp wrote:

 
 
 
 
 
 
 
 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
 Sent: January-25-10 5:53 PM
 To: Ernie Kemp
 Cc: 'PHP General List'
 Subject: Re: [PHP] Upload file on IE8
 
  
 
 On Mon, 2010-01-25 at 17:41 -0500, Ernie Kemp wrote:
 
 
 
  
 
 Good Day,
 
  
 
 I’m having an issue with IE8, when I go to load a file the 
 program is not filling the $_FILES['user_file']['type']  .
 
  
   When I display  “echo  Start.$_FILES['pix']['type'].End;”  
 in IE8 I get “StartEnd” with nothing in between.  I expected “image/pjpeg.
  
 On FireFox I get “image/jpeg.
  
 Any suggestions?
 Thanks,
 /Ernie
  
 
 
 
 What do the other $_FILES fields say? Are they populated correctly?
 
 I wouldn't rely on anything sent from the browser. IE is known to send the 
 mime type that matches the extension, not the contents of the file, and for 
 .jpg images it sends a different mime to every other browser anyway, so it's 
 pretty unreliable. 
 
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 
 
 
 With IE8,
 
   Using $_FILES the array results for  ‘name’ has the name of the file 
 but ‘type’, ‘tmp_name’ and ‘size’ are blanks.
 
  I tried enabling the “file path location” in IE8 option but the results 
 are the same for $_FILES. 
 
  
 
 
Firefox works displays all the values in the $_FILES array.
 
 There must be a better way. Suggestions?
 
 Thanks,
 
 /Ernie
 


Don't use the value. There are a few different ways in PHP to get the
mime type of a file, which it does based on the contents of the file and
not its extension. This prevents someone from uploading an executable
virus for example by just changing the last three letters of the
filename.

Have a look at fileinfo() for this sort of thing.

Thanks,
Ash
http://www.ashleysheridan.co.uk




[PHP] Creating an Entire .html page with PHP

2010-01-25 Thread deal...@gmail.com

Hi Folks,

I would like to create an entire .html page gathered from database  
content mixed with html etc. and be able to save the page...



like:

--- save all this pre made content as .html page

html
head
...  stuff
/head
body
...  stuff
...  stuff with database query results...
...  stuff
/body
/html

Q: Is there a function that might help with saving the whole content  
as .html page?




Thanks,
deal...@gmail.com
[db-10]


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



Re: [PHP] Creating an Entire .html page with PHP

2010-01-25 Thread Ashley Sheridan
On Mon, 2010-01-25 at 17:00 -0800, deal...@gmail.com wrote:

 Hi Folks,
 
 I would like to create an entire .html page gathered from database  
 content mixed with html etc. and be able to save the page...
 
 
 like:
 
 --- save all this pre made content as .html page
 
 html
 head
 ...  stuff
 /head
 body
 ...  stuff
 ...  stuff with database query results...
 ...  stuff
 /body
 /html
 
 Q: Is there a function that might help with saving the whole content  
 as .html page?
 
 
 
 Thanks,
 deal...@gmail.com
 [db-10]
 
 


$fh = fopen(page.html,w);
fwrite($fh, $htmlcode);


Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Creating an Entire .html page with PHP

2010-01-25 Thread Angus Mann
- Original Message - 
From: deal...@gmail.com

To: PHP-General php-general@lists.php.net
Sent: Tuesday, January 26, 2010 11:00 AM
Subject: [PHP] Creating an Entire .html page with PHP



Hi Folks,

I would like to create an entire .html page gathered from database 
content mixed with html etc. and be able to save the page...



like:

--- save all this pre made content as .html page

html
head
...  stuff
/head
body
...  stuff
...  stuff with database query results...
...  stuff
/body
/html

Q: Is there a function that might help with saving the whole content  as 
.html page?




Thanks,
deal...@gmail.com
[db-10]


Not really...no. The fact that you're asking this question makes me think 
you should start with a less ambitious goal than you describe. Terms like 
saving the whole content as a .html page and content mixed with html are 
pretty meaningless, I'm afraid.


Try generating a few ordinary pages before you throw a database into the 
mix.



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



[PHP] Re: Creating an Entire .html page with PHP

2010-01-25 Thread Al



On 1/25/2010 8:00 PM, deal...@gmail.com wrote:

Hi Folks,

I would like to create an entire .html page gathered from database
content mixed with html etc. and be able to save the page...


like:

--- save all this pre made content as .html page

html
head
... stuff
/head
body
... stuff
... stuff with database query results...
... stuff
/body
/html

Q: Is there a function that might help with saving the whole content as
.html page?



Thanks,
deal...@gmail.com
[db-10]



rename(APPLIC_DB_FILE, APPLIC_DB_FILE . 'BAK'); //make a backup
$serTxt = serialize($dbTable);
if(!file_put_contents(APPLIC_DB_FILE, $serTxt, LOCK_EX))
die(div style=\color:red; margin:10em auto auto auto\Major error in 
upDateDBTable(). Contact tech support/div);


$dbTable = unserialize(file_get_contents(APPLIC_DB_FILE)); //Current application 
file




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



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

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


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

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

Ravi



On Mon, Jan 25, 2010 at 3:49 PM, D. Dante Lorenso da...@lorenso.com wrote:
 J Ravi Menon wrote:

 PHP does expose sys V shared-memory apis (shm_* functions):
 http://us2.php.net/manual/en/book.sem.php


 I will look into this.  I really need a key/value map, though and would
 rather not have to write my own on top of SHM.


 If you already have apc installed, you could also try:
 http://us2.php.net/manual/en/book.apc.php
 APC also allows you to store user specific data too (it will be in a
 shared memory).


 I've looked into the apc_store and apc_fetch routines:
 http://php.net/manual/en/function.apc-store.php
 http://www.php.net/manual/en/function.apc-fetch.php
 ... but quickly ran out of memory for APC and though I figured out how to
 configure it to use more (adjust shared memory allotment), there were other
 problems.  I ran into issues with logs complaining about cache slamming
 and other known bugs with APC version 3.1.3p1.  Also, after several million
 values were stored, the APC storage began to slow down *dramatically*.  I
 wasn't certain if APC was using only RAM or was possibly also writing to
 disk.  Performance tanked so quickly that I set it aside as an option and
 moved on.


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


 I will run more tests against MongoDB.  Initially I tried to use it to store
 everything.  If I only store my indexes, it might fare better. Certainly,
 though, running queries and updates against a remote server will always be
 slower than doing the lookups locally in ram.


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

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

 -- Dante


 On Sun, Jan 24, 2010 at 9:39 AM, D. Dante Lorenso da...@lorenso.com
 wrote:

 shiplu wrote:

 On Sun, Jan 24, 2010 at 3:11 AM, D. Dante Lorenso da...@lorenso.com
 wrote:

 All,

 I'm loading millions of records into a backend PHP cli script that I
 need to build a hash index from to optimize key lookups for data that
 I'm importing into a MySQL database.  The problem is that storing this
 data in a PHP array is not very memory efficient and my millions of
 records are consuming about 4-6 GB of ram.

 What are you storing? An array of row objects??
 In that case storing only the row id is will reduce the memory.

 I am querying a MySQL database which contains 40 million records and
 mapping
 string columns to numeric ids.  You might consider it normalizing the
 data.

 Then, I am importing a new 40 million records and comparing the new
 values
 to the old values.  Where the value matches, I update records, but where
 they do not match, I insert new records, and finally I go back and delete
 old records.  So, the net result is that I have a database with 40
 million
 records that I need to sync on a daily basis.

 If you are loading full row objects, it will take a lot of memory.
 But if you just load the row id values, it will significantly decrease
 the memory amount.

 For what I am trying to do, I just need to map a string value (32 bytes)
 to
 a 

Re: [PHP] Creating an Entire .html page with PHP

2010-01-25 Thread deal...@gmail.com


On Jan 25, 2010, at 4:59 PM, Ashley Sheridan wrote:




$fh = fopen(page.html,w);
fwrite($fh, $htmlcode);





Thanks so much Ashley and ALL, this looks like it will work fine.

BTW: Sorry if I didn't make myself clear - I just wanted to grab some  
data like a person from a contacts file and be able to save a  
static .html web page with their data - etc.


... this little test seems to work

I added fclose($fh); at the end (correct?)


- - - - - -


?php

// got some data with query 'get'...

$addthis = ' my name is:  ';

$fh = fopen(testpage.html,w);

$htmlcode = '!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0  
Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1- 
transitional.dtd

html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/html; charset=UTF-8 /
titleUntitled Document/title
/head

body

this is a testbr /br /'.$addthis.'br /'.$row_get['FirstName'].'  
'.$row_get['LastName'].'br /


this is a test 2


/body
/html
';


fwrite($fh, $htmlcode);

fclose($fh);

?





Thanks,
deal...@gmail.com
[db-10]


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



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

2010-01-25 Thread Shawn McKenzie
Joseph Thayne 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.

5. A tear is rendered in the space time continuum!

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

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



Re: [PHP] Creating an Entire .html page with PHP

2010-01-25 Thread Shawn McKenzie
deal...@gmail.com wrote:
 
 On Jan 25, 2010, at 4:59 PM, Ashley Sheridan wrote:
 
 

 $fh = fopen(page.html,w);
 fwrite($fh, $htmlcode);



 
 Thanks so much Ashley and ALL, this looks like it will work fine.
 
 BTW: Sorry if I didn't make myself clear - I just wanted to grab some
 data like a person from a contacts file and be able to save a static
 .html web page with their data - etc.
 
 ... this little test seems to work
 
 I added fclose($fh); at the end (correct?)
 
 
 - - - - - -
 
 
 ?php
 
 // got some data with query 'get'...
 
 $addthis = ' my name is:  ';
 
 $fh = fopen(testpage.html,w);
 
 $htmlcode = '!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
 Transitional//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html; charset=UTF-8 /
 titleUntitled Document/title
 /head
 
 body
 
 this is a testbr /br /'.$addthis.'br /'.$row_get['FirstName'].'
 '.$row_get['LastName'].'br /
 
 this is a test 2
 
 
 /body
 /html
 ';
 
 
 fwrite($fh, $htmlcode);
 
 fclose($fh);
 
 ?
 
 
 
 
 
 Thanks,
 deal...@gmail.com
 [db-10]
 

file_put_contents() is s much easier.

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

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



Re: [PHP] Creating an Entire .html page with PHP

2010-01-25 Thread deal...@gmail.com


On Jan 25, 2010, at 6:23 PM, Shawn McKenzie wrote:


file_put_contents() is s much easier.


Thanks Shawn I'll check that out ...

- I see it says : This function is identical to calling fopen(),  
fwrite() and fclose() successively to write data to a file.



my newbie brain likes that!


Thanks,
deal...@gmail.com
[db-10]


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



[PHP] If the first four characters are 0000, then do {}

2010-01-25 Thread John Taylor-Johnston

I am reading the manual: http://ca.php.net/manual/en/ref.strings.php

$mydata-restored = -00-00;

How do I express this? If the first four characters are , then do {}

What I am looking for is in strpos(), no?

if ()
{
}

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



Re: [PHP] If the first four characters are 0000, then do {}

2010-01-25 Thread Daniel Brown
On Mon, Jan 25, 2010 at 21:36, John Taylor-Johnston
john.taylor-johns...@cegepsherbrooke.qc.ca wrote:
 I am reading the manual: http://ca.php.net/manual/en/ref.strings.php

 $mydata-restored = -00-00;

?php

$o[] = '0942-23-23';
$o[] = '-00-00';
$o[] = '1238-00-00';
$o[] = '0001-23-45';
$o[] = '-11-22';

for($i=0;$icount($o);$i++) {
if(preg_match('/^[0]{4,}\-/U',$o[$i])) {
echo Offset #.$i. matches: .$o[$i].PHP_EOL;
}
}
?

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers?  Ask me how we can fit your budget!

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



Re: [PHP] If the first four characters are 0000, then do {}

2010-01-25 Thread Angus Mann
- Original Message - 
From: John Taylor-Johnston john.taylor-johns...@cegepsherbrooke.qc.ca

To: PHP-General php-general@lists.php.net
Sent: Tuesday, January 26, 2010 12:36 PM
Subject: [PHP] If the first four characters are , then do {}



I am reading the manual: http://ca.php.net/manual/en/ref.strings.php

$mydata-restored = -00-00;

How do I express this? If the first four characters are , then do {}

What I am looking for is in strpos(), no?

if ()
{
}



if (substr($mydata,0,4) == {
   Do stuff
}


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



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

2010-01-25 Thread Michael A. Peters

Shawn McKenzie wrote:

Joseph Thayne 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.


5. A tear is rendered in the space time continuum!



6. An alternate version of Dr. Rodney McKay from an alternate universe 
appears, and goes by Rod.


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



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/


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

2010-01-25 Thread APseudoUtopia
On Mon, Jan 25, 2010 at 10:00 PM, Michael A. Peters mpet...@mac.com wrote:
 Shawn McKenzie wrote:

 Joseph Thayne 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.

 5. A tear is rendered in the space time continuum!


 6. An alternate version of Dr. Rodney McKay from an alternate universe
 appears, and goes by Rod.


7. Then you realize that MySQL handles certain things, such as the
aforementioned problem, very badly and does not comply to standards
and isn't even ACID compliant, so you then switch to PostgreSQL
instead.

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



[PHP] In need of better __FILE__, __LINE__ and __FUNCTION__ magic variables

2010-01-25 Thread Daevid Vincent
Like you, I have many little functions that are useful for debugging in a
page.

The problem is that when you start to pepper them around, whilst debugging,
you can often times forget where you left them. A search isn't always
helpful since I sometimes leave them in the code, but commented out, so I
end up finding dozens of matches.

What I need are some variables that tell me the current calling file, line
and function I'm in. Then when I see some debug info on the screen, I know
exactly where it came from.

http://www.php.net/manual/en/language.constants.predefined.php are for the
most part useless for this task, as they tell you information about the
file, line and function name itself. This is a subtle but significant
difference.

Say I have a typical setup:

common.inc.php -- has all my helper routines and fancy debug functions.
mywebpage.inc.php -- the functions for mywebpage as I follow MVC logic.
mywebpage.php -- the page I'm trying to work on and debug.

If I place a print_x($foo) in mywebpage.inc.php somewhere, lets say in a
function insert_into_database() on line 69, I would expect that __FILE__,
__LINE__ and __FUNCTION__ to reflect all of that. It should return with
mywebpage.inc.php, 69 and insert_into_database respectively.

What in fact happens is that I get common.inc.php, 642, print_x. If I
use $_SERVER['PHP_SELF'] instead of __FILE__ then I get mywebpage.php
(not mywebpage.inc.php as desired)

Now, the __FILE__, __LINE__ and __FUNCTION__ have their merit in some
cases, but I think there needs to be another set of magic variables that
are more dynamic and work as I suggest. Perhaps a __CFILE__, __CLINE__ and
__CFUNCTION__  with the C prefix for Current or Calling

/**
* Print out a pretty, portlet, styled version of an array
*
* @paramarray   $array  Array to print out
* @paramboolean $var_dump use either print_r (false/default) or
var_dump
* @paramstring $string if set, this will print out in the title of
the debug portlet
*/
function print_x($array, $var_dump=false, $string='')
{
if (!is_array($array))
{
echo 'b'.$_SERVER['PHP_SELF'].'::'.__FUNCTION__.(Not An
Array) $string/bbr/\n;
return;
}
?
div class=debug
div class=headerh2?= $_SERVER['PHP_SELF'].'::'.__FUNCTION__
?()?= $string ?/h2/div
div class=content
?php
print div class=\debug\pre style=\padding: 0; margin:
0;\\n;

if ($var_dump)
{
var_dump($array);
}
else
{
foreach($array as $k = $v)
if (is_bool($v))
$array[$k] = ($v === true) ?
'TRUE':'FALSE';
elseif (is_object($v))
$array[$k] =
'CLASS::'.get_class($v);

print_r( $array );
}

print /pre\n/div\n;
?
/div
/div
?php
}

function debug_print($var, $name='MY_VARIABLE')
{
if (is_array($var))
{
print_x($var, false, $name);
return;
}

echo 'span class=debug'.__FILE__.'@'.__LINE__.'b'.$name.'/b
= '.$var./spanbr/\n;
}


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



[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] If the first four characters are 0000, then do {}

2010-01-25 Thread Daevid Vincent
 -Original Message-
 From: paras...@gmail.com [mailto:paras...@gmail.com] On 
 Behalf Of Daniel Brown
 Sent: Monday, January 25, 2010 6:43 PM
 To: John Taylor-Johnston
 Cc: PHP-General
 Subject: Re: [PHP] If the first four characters are , then do {}
 
 On Mon, Jan 25, 2010 at 21:36, John Taylor-Johnston
 john.taylor-johns...@cegepsherbrooke.qc.ca wrote:
  I am reading the manual: http://ca.php.net/manual/en/ref.strings.php
 
  $mydata-restored = -00-00;
 
 ?php
 
 $o[] = '0942-23-23';
 $o[] = '-00-00';
 $o[] = '1238-00-00';
 $o[] = '0001-23-45';
 $o[] = '-11-22';
 
 for($i=0;$icount($o);$i++) {
 if(preg_match('/^[0]{4,}\-/U',$o[$i])) {
 echo Offset #.$i. matches: .$o[$i].PHP_EOL;
 }
 }
 ?

Holy macaroni. Talk about overkill!

if (substr($mydata-restored,0,4) == ) { }

Or in your very specific case you could do the harder way and note that
strings work like simple arrays too in a way, so $mydata-restored{0}
through $mydata-restored{3} should all be '0' ( note the {} and not [] ).
You can use a forloop or just manually check them all with  or || or
whatever logic you feel comfortable with. But the substr is by far the
simplest.


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



[PHP] SQL question

2010-01-25 Thread Skip Evans

Hey all,

I have an SQL query that's stumping me.

I have two date variables, $start and $end that are in 
mm/dd/ format and two database fields, start_date and 
no_donations. The start date is mm/dd/ format and 
no_donations is an integer that represents the number of 
months from start_date that donations will be made.


So if start date is say 02/01/2010 and no_dations is 4 then 
donations will be made four times from the start date for four 
months.


What I need to do is come up with a query that will determine 
if the start_date + no_donations falls within $start and $end.


But I'm pretty stumped. How can I convert start_date + 
no_donations in the database to the date when the last 
donation will take place so I'll now if the donations fall 
between $start and $end?


Any suggestions would be very help and appreciated,
Skip

--

Skip Evans
PenguinSites.com, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://penguinsites.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

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



Re: [PHP] In need of better __FILE__, __LINE__ and __FUNCTION__ magic variables

2010-01-25 Thread Robert Cummings

Daevid Vincent wrote:

Like you, I have many little functions that are useful for debugging in a
page.

The problem is that when you start to pepper them around, whilst debugging,
you can often times forget where you left them. A search isn't always
helpful since I sometimes leave them in the code, but commented out, so I
end up finding dozens of matches.

What I need are some variables that tell me the current calling file, line
and function I'm in. Then when I see some debug info on the screen, I know
exactly where it came from.


Use debug_backtrace() to capture the information from within the 
print_debug() or other deeper function. Just grab the second (or 
further) stack item that corresponds to the location where print_debug() 
was called.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



[PHP] Speed of sending email .. can I put them in a queue rather than wait?

2010-01-25 Thread Angus Mann
Hi all.

I'm currently using the phpmailer class from phpmailer.worxware.com to send 
datatbase -populated emails to clients.

At the moment I'm runninng PHP on Windows and using the built-in sendmail 
equivalent packaged with XAMPP. It uses a remote SMTP that authenticates by 
prior logging into a POP account.

The number of emails sent is very small. Each one is only sent after a user 
fills out a form and presses send.

But there is a noticable lag of about 5 or sometimes 10 seconds after pressing 
send before the user sees the Mail sent page. I presume the reason for the 
lag is the time spent logging on and off a remote POP, then SMTP server, 
transferring the data etc.

It would be better if this happened in the background - that is, the user could 
get on with doing his next task while the emails sat in a queue in the 
backgorund, being lined up and sent without PHP waiting for the process to 
finish.

Can anybody recommend a good way of doing this? Is Mercury Mail going to help 
me here?



Re: [PHP] If the first four characters are 0000, then do {}

2010-01-25 Thread Paul M Foster
On Mon, Jan 25, 2010 at 09:36:50PM -0500, John Taylor-Johnston wrote:

 I am reading the manual: http://ca.php.net/manual/en/ref.strings.php

 $mydata-restored = -00-00;

 How do I express this? If the first four characters are , then do {}

 What I am looking for is in strpos(), no?

 if ()
 {
 }

From what I understand, strpos() faster than a lot of other similar
string functions and much faster than regexps. You could do:

if (strpos($mydata-restored, '') === 0) {
do_stuff();
}

Paul

-- 
Paul M. Foster

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



Re: [PHP] In need of better __FILE__, __LINE__ and __FUNCTION__ magic variables

2010-01-25 Thread Paul M Foster
On Mon, Jan 25, 2010 at 10:59:43PM -0500, Robert Cummings wrote:

 Daevid Vincent wrote:
 Like you, I have many little functions that are useful for debugging in a
 page.

 The problem is that when you start to pepper them around, whilst debugging,
 you can often times forget where you left them. A search isn't always
 helpful since I sometimes leave them in the code, but commented out, so I
 end up finding dozens of matches.

 What I need are some variables that tell me the current calling file, line
 and function I'm in. Then when I see some debug info on the screen, I know
 exactly where it came from.

 Use debug_backtrace() to capture the information from within the
 print_debug() or other deeper function. Just grab the second (or
 further) stack item that corresponds to the location where print_debug()
 was called.

+1

Or you can use debug_print_backtrace(), which directly outputs the
backtrace. I do this when my error handler encounters E_USER_ERROR and
the like.

Paul

-- 
Paul M. Foster

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



RE: [PHP] If the first four characters are 0000, then do {}

2010-01-25 Thread Daevid Vincent
 -Original Message-
 From: Paul M Foster [mailto:pa...@quillandmouse.com] 
 Sent: Monday, January 25, 2010 8:05 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] If the first four characters are , then do {}
 
 On Mon, Jan 25, 2010 at 09:36:50PM -0500, John Taylor-Johnston wrote:
 
  I am reading the manual: http://ca.php.net/manual/en/ref.strings.php
 
  $mydata-restored = -00-00;
 
  How do I express this? If the first four characters are 
 , then do {}
 
  What I am looking for is in strpos(), no?
 
  if ()
  {
  }
 
 From what I understand, strpos() faster than a lot of other similar
 string functions and much faster than regexps. You could do:
 
 if (strpos($mydata-restored, '') === 0) {
   do_stuff();
 }

Ah. Clever use of the == 0 (tripple equals not necessary).
The OP needs to know if it's the first 4 or not and so position 0 would be
the start. Very nice.

Now, if his data is always of the format -XX-XX as it was illustrated,
then this will also work

if (strpos($mydata-restored, '-') !== false) { do stuff; } 

(note the hyphen) and you should check the === false


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



Re: [PHP] Speed of sending email .. can I put them in a queue rather than wait?

2010-01-25 Thread Paul M Foster
On Tue, Jan 26, 2010 at 02:02:18PM +1000, Angus Mann wrote:

 Hi all.
 
 I'm currently using the phpmailer class from phpmailer.worxware.com to send 
 datatbase -populated emails to clients.
 
 At the moment I'm runninng PHP on Windows and using the built-in sendmail 
 equivalent packaged with XAMPP. It uses a remote SMTP that authenticates by 
 prior logging into a POP account.
 
 The number of emails sent is very small. Each one is only sent after a user 
 fills out a form and presses send.
 
 But there is a noticable lag of about 5 or sometimes 10 seconds after 
 pressing send before the user sees the Mail sent page. I presume the 
 reason for the lag is the time spent logging on and off a remote POP, then 
 SMTP server, transferring the data etc.
 
 It would be better if this happened in the background - that is, the user 
 could get on with doing his next task while the emails sat in a queue in the 
 backgorund, being lined up and sent without PHP waiting for the process to 
 finish.
 
 Can anybody recommend a good way of doing this? Is Mercury Mail going to help 
 me here?
 

If this were me, I'd set up a mailserver on the web machine and send
mail to it instead of using phpmailer to connect directly to a distant
mailserver. The authentication between phpmailer and the local
mailserver should be near instantaneous, and you can let the local
mailserver deal with transferring mails in its own sweet time. I don't
know if there's a mailserver included in XAMPP installations, but if so,
I'd do that. In fact, if you're just sending simple emails, you could
use PHP's built-in mail() function, which will connect directly to the
local mailserver without further configuration.

Paul

-- 
Paul M. Foster

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



Re: [PHP] If the first four characters are 0000, then do {}

2010-01-25 Thread Andrew Ballard
On Mon, Jan 25, 2010 at 11:12 PM, Daevid Vincent dae...@daevid.com wrote:
 From what I understand, strpos() faster than a lot of other similar
 string functions and much faster than regexps. You could do:

 if (strpos($mydata-restored, '') === 0) {
       do_stuff();
 }

 Ah. Clever use of the == 0 (tripple equals not necessary).
 The OP needs to know if it's the first 4 or not and so position 0 would be
 the start. Very nice.


The triple equals IS necessary. If '' is not found at all in
$mydata-restored, strpos() will return false, and (false == 0) in
PHP.

Andrew

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



Re: [PHP] SQL question

2010-01-25 Thread Paul M Foster
On Mon, Jan 25, 2010 at 09:54:40PM -0600, Skip Evans wrote:

 Hey all,

 I have an SQL query that's stumping me.

 I have two date variables, $start and $end that are in
 mm/dd/ format and two database fields, start_date and
 no_donations. The start date is mm/dd/ format and
 no_donations is an integer that represents the number of
 months from start_date that donations will be made.

 So if start date is say 02/01/2010 and no_dations is 4 then
 donations will be made four times from the start date for four
 months.

 What I need to do is come up with a query that will determine
 if the start_date + no_donations falls within $start and $end.

 But I'm pretty stumped. How can I convert start_date +
 no_donations in the database to the date when the last
 donation will take place so I'll now if the donations fall
 between $start and $end?

 Any suggestions would be very help and appreciated,

If there's a way to do this in SQL itself, I don't know what it is. But
in my opinion, you need a date class which can do date comparisons.

(If you end up programming one yourself, save yourself some time and
convert all dates to Julian day numbers internally. This saves massive
amounts of computation in determining intervals and durations.
Typically, coders try to store dates in unix timestamps internally, and
then add 86400 seconds for every day to calculate intervals and such.
This is often inaccurate. Julian days are far more accurate.)

Paul

-- 
Paul M. Foster

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



Re: [PHP] If the first four characters are 0000, then do {}

2010-01-25 Thread Paul M Foster
On Mon, Jan 25, 2010 at 08:12:43PM -0800, Daevid Vincent wrote:

  -Original Message-
  From: Paul M Foster [mailto:pa...@quillandmouse.com]
  Sent: Monday, January 25, 2010 8:05 PM
  To: php-general@lists.php.net
  Subject: Re: [PHP] If the first four characters are , then do {}
 
  On Mon, Jan 25, 2010 at 09:36:50PM -0500, John Taylor-Johnston wrote:
 
   I am reading the manual: http://ca.php.net/manual/en/ref.strings.php
  
   $mydata-restored = -00-00;
  
   How do I express this? If the first four characters are
  , then do {}
  
   What I am looking for is in strpos(), no?
  
   if ()
   {
   }
 
  From what I understand, strpos() faster than a lot of other similar
  string functions and much faster than regexps. You could do:
 
  if (strpos($mydata-restored, '') === 0) {
  do_stuff();
  }
 
 Ah. Clever use of the == 0 (tripple equals not necessary).

No, the === was purposeful, since strpos can return false if there's no
match. If you simply use == 0, it will trigger on both false, and the
0 index. If you use !== false, you're only testing for no match.

Paul

-- 
Paul M. Foster

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



Re: [PHP] SQL question

2010-01-25 Thread Michael A. Peters

Paul M Foster wrote:


Typically, coders try to store dates in unix timestamps internally, and
then add 86400 seconds for every day to calculate intervals and such.
This is often inaccurate. Julian days are far more accurate.)

Paul



I use seconds from epoch in the database simply because it works so well 
with the php date() function.


If you need something where Julian day really is better, I assume it 
isn't that hard to convert between posix and julian day, though it seems 
odd to me that it isn't part of the date() function. It probably should be.


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



Re: [PHP] SQL question

2010-01-25 Thread Michael A. Peters

Michael A. Peters wrote:



If you need something where Julian day really is better, I assume it 
isn't that hard to convert between posix and julian day, though it seems 
odd to me that it isn't part of the date() function. It probably should be.




Looks like unixtojd() and jdtounix() do it.

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