[PHP] Unit Tests for Cache Class

2011-01-26 Thread Sebastian Detert

Hi all,

I'm just writing a small cache class to optimize my database connection. 
I want to use three different stages to store and receive my data as 
fast as possible.


1) fast
get data from class variable if existing

2) mid
get data from memcache if existing
- save result as class variable

3) slowest:
sql query - receive data from database
- save result to memcache
- save result as class variable

How would you write (unit) tests for such a class? What is the best way 
to prove, that all data was stored correctly, even after data 
manipulations like insert/update/delete?


I'm looking forward to your suggestions,
Sebastian






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



[PHP] Singleton with variable parameters

2010-12-15 Thread Sebastian Detert

Hi guys,

I am trying to generate an abstract Singleton class for use in arbitrary 
classes, like


class Foo extends Singleton {}

and generate a new class with Foo - getInstance();

How can I manage to use this with an unkown number of parameters like 
Foo - getInstance('a', 'b'); ?


Something like self::$instance = call_user_func (array(static , 
__construct), func_get_args()); instead of self::$instance = new 
self; doesn't work and an eval() is too slow.


I hope you can help me.

Thanks,
Sebastian

class Singleton
{
static private $instance = null;
static public function getInstance()
{
 if http://www.phpbar.de/w/if(null === self::$instance) {
self::$instance = new self;
}
return http://www.phpbar.de/w/returnself::$instance;
}
private function __construct(){}
private function __clone(){}
}



[PHP] Model View Concepts

2010-10-22 Thread Sebastian Detert

Hi all,

I'm currently searching for any code snippets, tutorials, howtos, 
concepts which explain different ways to collect all type of data/input 
(i.e. inside a class, xml, json string whatever) and create independent 
html files (i.e. different designs), xml files, pdf files, etc. out of 
that pool of data. Do you have any urls or own experience you could share?


Thanks,
Sebastian

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



[PHP] Unicode - Entitiy Encoding

2010-10-20 Thread Sebastian Detert

Hi all,

I'm stuck with this problem: I am trying to convert a text with any kind 
of unicode characters to its octet and entity equivalents.


For example:
Ë is #203; as octet and Euml; as entity
Đ is #272; as octet and Dstrok; as entity

My code works fine for some characters ( Ë works fine, but Đ fails at 
entity encoding). Do you have a hint, how to solve this?


I try to get the octet encoding with mb_encode_numericentity which works 
fine for everything


$convmap = array(
0x22, 0x22, 0, 0x, # 
0x26, 0x27, 0, 0x, # '
0x3c, 0x3c, 0, 0x, # 
0x3d, 0x3d, 0, 0x, # 
0x80, 0x, 0, 0x,
);
$oct_string = mb_encode_numericentity($test, $convmap, 'UTF-8');

I try to get all entity encodings with htmlentities

$entity_string = htmlentities($test, ENT_QUOTES, 'UTF-8');

But that fails for some characters like Đ. Is there a better way to get 
all entity encodings?


Thanks,
Sebastian

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



Re: [PHP] Execute a php page and don't wait for it to finish

2010-10-19 Thread Sebastian Detert

Ferdi schrieb:

Hi List,

I have a php page that updates data from one database to another when it is
run.
My query is, how can I trigger the execution of this update page from
another php / javascript without the calling page having to wait for the
update page to finish?
Basically, I think the update page needs to use:
ignore_user_abort(1);
set_time_limit(0); // I don't think the script will take more than 1 min.

At the other end I found this:
1)
http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/
2) On that page a user suggested using *pclose(popen(‘/usr/bin/php
/path/to/something.php  /dev/null ’, ‘r’)*
**However, I need this to be usable on windows servers also.
3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for
me?

Which of the above 3 options is the better one?
Other suggestions are welcome :)

Thanks and Regards,
Ferdi

  
1) I guess an asynchronous ajax request is what you are looking for. But 
it won't work on command line.


2) Maybe 
http://robert.accettura.com/blog/2006/09/14/asynchronous-processing-with-php/ 
could help you, but I never tried that.


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



Re: [PHP] Firs Day Of Week UNIX

2010-10-19 Thread Sebastian Detert

Don Wieland schrieb:

Hi gang,

I need a bailout.

I have a fields called sys_first_day_of_week and the user can select 
one value which will be from a menu with these options:


Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday

Based on this Preference and TODAYS DATE, I want to calculate the 
first day of the week.


So if my preference is Monday and Today's date is 10/19/2010, I want 
to return a value of: 1287374400 (which is 10/18/2010)


if my preference is Wednesday and Today's date is 10/19/2010, I want 
to return a value of: 1286942400 (which is 10/13/2010)


Appreciate any help.

Don

I'm not sure: You are searching the date of the last given weekdate?

$sys_first_day_of_week: Monday = 1, ..., Saturday = 6, Sunday = 0

Try this one: date seems to be correct, but value is different, maybe 
different time zone?


if ( date('w')  $sys_first_day_of_week ) {
 $value = mktime(0,0,0,date('n'),date('j'),date('Y')) - ( 7 + date('w') 
- $sys_first_day_of_week ) * 24 * 60 * 60;

}
else {
 $value = mktime(0,0,0,date('n'),date('j'),date('Y')) - ( date('w') - 
$sys_first_day_of_week ) * 24 * 60 * 60;

}



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



Re: [PHP] References in Sessions

2010-10-14 Thread Sebastian Detert

Alexander Schrijver schrieb:

Is my message unclear? or didn't anyone  ran into this problem?

  
If you want an atomic solution, you need to save the session to your 
database. How often do you need to delete data? Isn't it better to 
delete at night when noone is online, or logout all users for some 
minutes while deleting? In addition to that I don't understand, why it 
is important to prevent deletion if a point is selected ... If you want 
to work with something that was deleted, print an error and that's it.


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



Re: [PHP] Text messaging from the web

2010-10-14 Thread Sebastian Detert

Paul M Foster schrieb:

Folks:

Being fairly geezerly, I know almost nothing about this, so be gentle.

Assuming someone entered information in a form on a website. Normally,
you would email the responses to someone. But what if you wanted to
send this information to a smartphone via text messaging?

Is this possible, given normal programming tools (PHP/Javascript), or
would you have to go through some commercial web to text messaging
gateway? Does anyone know if this could be done, and how?

Paul

  
I guess you have to connect to any kind of interface of a commercial 
provider. I searched for php sms on google and got several tutorials 
and informations. Just give it a try.


Sebastian

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



Re: [PHP] Text messaging from the web

2010-10-14 Thread Sebastian Detert

Larry Martell schrieb:

On Thu, Oct 14, 2010 at 9:45 AM, Paul M Foster pa...@quillandmouse.com wrote:
  

Folks:

Being fairly geezerly, I know almost nothing about this, so be gentle.

Assuming someone entered information in a form on a website. Normally,
you would email the responses to someone. But what if you wanted to
send this information to a smartphone via text messaging?

Is this possible, given normal programming tools (PHP/Javascript), or
would you have to go through some commercial web to text messaging
gateway? Does anyone know if this could be done, and how?



You can send a text message via email:

Verizon: 10digitphonenum...@vtext.com
ATT: 10digitphonenum...@txt.att.net
Sprint: 10digitphonenum...@messaging.sprintpcs.com
T-Mobile: 10digitphonenum...@tmomail.net
Nextel: 10digitphonenum...@messaging.nextel.com
Cingular: 10digitphonenum...@cingularme.com
Virgin Mobile: 10digitphonenum...@vmobl.com
Alltel: 10digitphonenum...@message.alltel.com
CellularOne: 10digitphonenum...@mobile.celloneusa.com
Omnipoint: 10digitphonenum...@omnipointpcs.com
Qwest: 10digitphonenum...@qwestmp.com

  
Me again ;) Is that for free? I just found this interesting site: 
http://www.tech-faq.com/how-to-send-text-messages-free.html


Re: [PHP] Text messaging from the web

2010-10-14 Thread Sebastian Detert

Larry Martell schrieb:

On Thu, Oct 14, 2010 at 10:01 AM, Sebastian Detert
php-maill...@elygor.de wrote:
  

Larry Martell schrieb:

On Thu, Oct 14, 2010 at 9:45 AM, Paul M Foster pa...@quillandmouse.com
wrote:


Folks:

Being fairly geezerly, I know almost nothing about this, so be gentle.

Assuming someone entered information in a form on a website. Normally,
you would email the responses to someone. But what if you wanted to
send this information to a smartphone via text messaging?

Is this possible, given normal programming tools (PHP/Javascript), or
would you have to go through some commercial web to text messaging
gateway? Does anyone know if this could be done, and how?


You can send a text message via email:

Verizon: 10digitphonenum...@vtext.com
ATT: 10digitphonenum...@txt.att.net
Sprint: 10digitphonenum...@messaging.sprintpcs.com
T-Mobile: 10digitphonenum...@tmomail.net
Nextel: 10digitphonenum...@messaging.nextel.com
Cingular: 10digitphonenum...@cingularme.com
Virgin Mobile: 10digitphonenum...@vmobl.com
Alltel: 10digitphonenum...@message.alltel.com
CellularOne: 10digitphonenum...@mobile.celloneusa.com
Omnipoint: 10digitphonenum...@omnipointpcs.com
Qwest: 10digitphonenum...@qwestmp.com



Me again ;) Is that for free? I just found this interesting site:
http://www.tech-faq.com/how-to-send-text-messages-free.html



Yes, you can send text messages for free this way.

  
I just tried it. I guess, it is only possible to use those E-Mails if 
you are a customer of that phone company, right? I tried it with my own 
provider (O2 germany),
sending an email to phonenum...@o2online.de failed, I had to activate 
that serviceby sending +OPEN to 6245, but every email to sms costs money ...
Are you sure it is possible to send sms to phones around the world to 
any provider? How do u distinguish between provider and country?


I'm sorry if I'm asking stupid stuff


Re: [PHP] Array / form processing

2010-10-08 Thread Sebastian Detert

Ron Piggott schrieb:

I am writing a custom shopping cart that eventually the cart will be
uploaded to PayPal for payment.  I need to be able to include the option
that the purchase is a gift certificate.



At present my add to cart function goes like this:

===
# Gift Certificate: 1 is a gift; 2 is personal use

if ( $gift_certificate == yes ) {
$gift = 1;
} else {
$gift = 2;
}

$_SESSION['life_coaching_order'][$product][$gift]['quantity'] = 
$_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;

===

Now I need to display the shopping cart contents.  I want to do this
through an array as the contents of the shopping cart are in a session
variable.  I start displaying the shopping cart contents by a FOREACH
loop:

===
foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference
= $value ) {
===

What I need help with is that I don't know how to test the value of $gift
in the above array if it is a 1 or 2 (which symbolizes this is a gift
certificate).

I have something like this in mind:
if ( $_SESSION['life_coaching_order'] == 2 ) {

But I don't know how to access all the components of the array while I am
going through the FOREACH loop.

By using a 1 or 2 I have made gift certificates their own product.  If
you a better method I could use please provide me with this feedback.

Ron

The Verse of the Day
Encouragement from God's Word
www.TheVerseOfTheDay.info


  
First at all, I wouldn't use 1 or 2 for defining important informations. 
use something like

define('ORDER_GIFT', 1);
define('ORDER_PERSONAL',2);

If you want to check all values of your array you can use several 
foreach loops like


foreach ($_SESSION['life_coaching_order'] AS $coaching_product = $tmp_array)
{
 foreach ($tmp_array as $coaching_gift = $tmp_array2)
 {
   switch ($coaching_gift)
 case ORDER_GIFT: break;

 case ORDER_PERSONAL: break;
)
 } 
}



Personally I would prefer writing a class like

class Order
{
  private $product;
  private $gift;
  private $quantity;

  const ORDER_GIFT=1;
  const ORDER_PERSONAL=2;

 function getGift() {
   return $this - gift;
 }
}

using

$_SESSION['life_coaching_order'][] = new Order();

foreach ( $_SESSION['life_coaching_order'] as $order )
{
 switch ( $order - getGift() )

 case ORDER_GIFT: break;

 case ORDER_PERSONAL: break;
  
} 


I hope that will help you,

Sebastian
http://elygor.de


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



Re: [PHP] PHP and HBCI?

2010-10-08 Thread Sebastian Detert
Do you have any specifications for HBCI interfaces? Socket connection, 
XML Exchange, DB Access ? If you have C code for such things, it should 
be possible to convert this to php code maybe


Stephan Ebelt schrieb:

On Fri, Oct 08, 2010 at 01:50:12PM +0100, a...@ashleysheridan.co.uk wrote:
  

How do you mean? Did you want to process payments? Or wad it more of an
actual banking thing you needed? I've not heard of hbci before, so can't
offer much information back.



HBCI is the german Home Banking Computer Interface which is supported by most
banks over here. There are free implementations such as the one used in gnucash
and some other projects: http://www.aquamaniac.de/sites/aqbanking/index.php
(sorry, site is german but code is english). I could not find a way to use
something like that from PHP code, only C and Java so far.

My goal for now would be to access bank account statements in order to show the
balances. I am not too eager to issue transactions.

thanks,
stephan



  

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

- Reply message -
From: Stephan Ebelt s...@shared-files.de
Date: Fri, Oct 8, 2010 13:37
Subject: [PHP] PHP and HBCI?
To: PHP php-general@lists.php.net


Hello,

is there a way to do HBCI banking with PHP?

stephan


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