[PHP] SimpleXMLElement and gb2312 or big5

2010-04-02 Thread Peter Pei
I use the following code to get rss and parse it, but the code  
occasionally have issues with gb2312 or big-5 encoded feeds, and fails to  
parse them. However other times may appear just okay. Any thoughts? Maybe  
SimpleXMLElement is simply not meant for other language encodings...


$page = file_get_contents($rss);
try {
$feed = new SimpleXMLElement($page);

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



[PHP] SimpleXMLElement occasionally fails to parse gb2312 or big5 feeds

2010-04-02 Thread Peter Pei


I use the following code to get rss and parse it, but the code  
occasionally have issues with gb2312 or big-5 encoded feeds, and fails to  
parse them. However other times may appear just okay. Any thoughts? Maybe  
SimpleXMLElement is simply not meant for other language encodings...


$page = file_get_contents($rss);
try {
$feed = new SimpleXMLElement($page);


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

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



Re: [PHP] Re: optimizing PHP for microseconds

2010-03-29 Thread Peter Lind
That's impossible to answer given the brief layout of what you've described.

However, rule of thumb: optimizing for microseconds only makes sense
when the microseconds together make up a significant amount of time.
An example might be in order:

for ($i = 0; $i  count($stuff); $i++)
{
  // do other stuffs
}

The above loop is NOT optimal (as most people will tell you) because
you'll be doing a count() every loop. However, there's an enormous
difference between doing 100 counts and 1.000.000 counts. Microseconds
only count when there's enough of them to make up seconds.

The best thing to do is adopt the normal good coding standards: don't
using functions in loops like the above, for instance.

However, be skeptic about tips: single-quotes are not faster than
double-quotes, for instance.

Regards
Peter

On 29 March 2010 10:28, Bastien Helders eldroskan...@gmail.com wrote:
 I have a question as a relatively novice PHP developper.

 Let's say you have this Intranet web application, that deals with the
 generation of file bundles that could become quite large (let say in the 800
 MB) after some kind of selection process. It should be available to many
 users on this Intranet, but shouldn't require any installation. Would it be
 a case where optimizing for microseconds would be recommended? Or would PHP
 not be the language of choice?

 I'm not asking to prove that there could be corner case where it could be
 useful, but I am genuinely interested as I am in the development of such a
 project, and increasing the performance of this web application is one of my
 goal.

 2010/3/28 Nathan Rixham nrix...@gmail.com

 mngghh, okay, consider me baited.

 Daevid Vincent wrote:
  Per Jessen wrote:
  Tommy Pham wrote:
 
  (I remember a list member, not mentioning his name, does optimization
  of PHP coding for just microseconds.  Do you think how much more he'd
  benefit from this?)
  Anyone who optimizes PHP for microseconds has lost touch with reality -
  or at least forgotten that he or she is using an interpreted language.
  But sometimes it's just plain fun to do it here on the list with
  everyone further optimizing the last optimized snippet :)
 
  Cheers,
  Rob.
 
  Was that someone me? I do that. And if you don't, then you're the kind of
  person I would not hire (not saying that to sound mean). I use single
  quotes instead of double where applicable. I use -- instead of ++. I use
  $boolean = !$boolean to alternate (instead of mod() or other incrementing
  solutions). I use LIMIT 1 on select, update, delete where appropriate.
 I
  use the session to cache the user and even query results. I don't use
  bloated frameworks (like Symfony or Zend or Cake or whatever else tries
 to
  be one-size-fits-all). The list goes on.

 That's not optimization, at best it's just an awareness of PHP syntax
 and a vague awareness of how the syntax will ultimately be interpreted.

 Using LIMIT 1 is not optimizing it's just saying you only want one
 result returned, the SQL query could still take five hours to run if no
 indexes, a poorly normalised database, wrong datatypes, and joins all
 over the place.

 Using the session to cache the user is the only thing that comes
 anywhere near to application optimisation in all you've said; and
 frankly I would take to be pretty obvious and basic stuff (yet pointless
 in most scenario's where you have to cater for possible bans and
 de-authorisations) - storing query results in a session cache is only
 ever useful in one distinct scenario, when the results of that query are
 only valid for the owner of the session, and only for the duration of
 that session, nothing more, nothing less. This is a one in a million
 scenario.

 Bloated frameworks, most of the time they are not bloated, especially
 when you use them properly and only include what you need on a need to
 use basis; then the big framework can only be considered a class or two.
 Sure the codebase seems more bloated, but at runtime it's easily
 negated. You can use these frameworks for any size project, enterprise
 included, provided you appreciated the strengths and weaknesses of the
 full tech stack at your disposal. Further, especially on enterprise
 projects it makes sense to drop development time by using a common
 framework, and far more importantly, to have a code base developers know
 well and can hit the ground running with.

 Generally unless you have unlimited learning time and practically zero
 budget constraints frameworks like the ones you mentioned should always
 be used for large team enterprise applications, although perhaps
 something more modular like Zend is suited. They also cover your own
 back when you are the lead developer, because on the day when a more
 experienced developer than yourself joins the project and points out all
 your mistakes, you're going to feel pretty shite and odds are very high
 that the project will go sour, get fully re-written or you'll have to
 leave due to stress (of being

Re: [PHP] Allowing multiple, simultaneous, non-blocking queries.

2010-03-26 Thread Peter Lind
Hi Richard

At the end of discussion, the best bet for something that approaches
a threaded version of multiple queries would be something like:
1. open connection to database
2. issue query using asynchronous call (mysql and postgresql support
this, haven't checked the others)
3. pick up result when ready

To get the threaded-ness, just open a connection per query you want to
run asynchronous and pick it up when you're ready for it - i.e.
iterate over steps 1-2, then do step 3 when things are ready.

Regards
Peter

On 26 March 2010 12:45, Richard Quadling rquadl...@googlemail.com wrote:
 Hi.

 As I understand things, one of the main issues in the When will PHP
 grow up thread was the ability to issue multiple queries in parallel
 via some sort of threading mechanism.

 Due to the complete overhaul required of the core and extensions to
 support userland threading, the general consensus was a big fat No!.


 As I understand things, it is possible, in userland, to use multiple,
 non-blocking sockets for file I/O (something I don't seem to be able
 to achieve on Windows http://bugs.php.net/bug.php?id=47918).

 Can this process be leveraged to allow for non-blocking queries?

 Being able to throw out multiple non-blocking queries would allow for
 the queries in parallel issue.

 My understanding is that at the base level, all queries are running on
 a socket in some way, so isn't this facility nearly already there in
 some way?


 Regards,

 Richard.

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-25 Thread Peter Lind
On 25 March 2010 19:37, Tommy Pham tommy...@gmail.com wrote:
 On Thu, Mar 25, 2010 at 3:55 AM, Per Jessen p...@computer.org wrote:
 Tommy Pham wrote:

 On Thu, Mar 25, 2010 at 1:46 AM, Per Jessen p...@computer.org wrote:
 * If you could implement threads and run those same queries in 2+
 threads, the total time saved from queries execution is 1/2 sec or
 more, which is pass along as the total response time reduced.  Is it
 worth it for you implement threads if you're a speed freak?

 Use mysqlnd - asynchronous mysql queries.


 You're assuming that everyone in the PHP world uses MySQL 4.1 or
 newer.  What about those who don't?

 They don't get to use threading, nor asynchronous mysql queries.

 Come on, you're asking about a future feature in PHP 7.x , but would
 like to support someone who is seriously backlevel on mysql??


 --
 Per Jessen, Zürich (16.9°C)


 I'm not talking about MySQL 4.0 or older.  I'm talking about other
 RDBMS.  I think you should open your eyes a bit wider and take a look
 at the bigger picture (Firebird, MSSQL, Oracle, PostgreSQL, etc).

http://www.php.net/manual/en/function.pg-send-query.php

Looks to me like the PHP postgresql library already handles that. Not
to mention: you're not presenting an argument for threads, you're
presenting an argument for implementing asynchronous queries in the
other DBMS libraries.

Of course, the problem could also be solved by introducing threads in
PHP. I'd personally guess modifying DBMS libraries would be less
costly, but as I haven't been involved in writing the PHP code my
guess isn't worth much.

Regards
Peter


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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-25 Thread Peter Lind
On 25 March 2010 20:09, Tommy Pham tommy...@gmail.com wrote:
 On Thu, Mar 25, 2010 at 12:02 PM, Peter Lind peter.e.l...@gmail.com wrote:
 On 25 March 2010 19:37, Tommy Pham tommy...@gmail.com wrote:
 On Thu, Mar 25, 2010 at 3:55 AM, Per Jessen p...@computer.org wrote:
 Tommy Pham wrote:

 On Thu, Mar 25, 2010 at 1:46 AM, Per Jessen p...@computer.org wrote:
 * If you could implement threads and run those same queries in 2+
 threads, the total time saved from queries execution is 1/2 sec or
 more, which is pass along as the total response time reduced.  Is it
 worth it for you implement threads if you're a speed freak?

 Use mysqlnd - asynchronous mysql queries.


 You're assuming that everyone in the PHP world uses MySQL 4.1 or
 newer.  What about those who don't?

 They don't get to use threading, nor asynchronous mysql queries.

 Come on, you're asking about a future feature in PHP 7.x , but would
 like to support someone who is seriously backlevel on mysql??


 --
 Per Jessen, Zürich (16.9°C)


 I'm not talking about MySQL 4.0 or older.  I'm talking about other
 RDBMS.  I think you should open your eyes a bit wider and take a look
 at the bigger picture (Firebird, MSSQL, Oracle, PostgreSQL, etc).

 http://www.php.net/manual/en/function.pg-send-query.php

 Looks to me like the PHP postgresql library already handles that. Not
 to mention: you're not presenting an argument for threads, you're
 presenting an argument for implementing asynchronous queries in the
 other DBMS libraries.

 Of course, the problem could also be solved by introducing threads in
 PHP. I'd personally guess modifying DBMS libraries would be less
 costly, but as I haven't been involved in writing the PHP code my
 guess isn't worth much.

 Regards
 Peter


 I'm presenting the argument for threading.  Per is presenting the work
 around using asynchronous queries via mysqlnd.  I did read that link a
 few days ago, Although the user can send multiple queries at once,
 multiple queries cannot be sent over a busy connection. If a query is
 sent while the connection is busy, it waits until the last query is
 finished and discards all its results.  Which sounds like threads -
 multiple connections to not run into that problem.


Have you looked into what it would cost in development to improve the
library? Have you compared that to the cost in development to
introduce threads into PHP? No, I don't think you're presenting the
argument for threading - but I don't expect you to see it that way.

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-25 Thread Peter Lind
On 25 March 2010 20:19, Tommy Pham tommy...@gmail.com wrote:
 Aren't all feature requests must be analyzed the same way?  Example,
 namespace, how many of us actually uses it now when there is an
 alternative solution- subfolders - that we've been using since who
 knows how long.  I don't know if threads was asked a feature prior
 namespace was implemented.


Yes, you're right. But feature requests are not equal: some present a
bigger payoff than others, and some will be more problematic to
implement than others. If a given language can solve the problems it
meets based on it's current structure, should you necessarily
implement new shiny features, that may present problems?

I'm not against threads in PHP per se ... I just haven't seen a very
convincing reason for them yet, which is why I'm not very positive
about the thing. The DB scenario could be handled without threads and
current libraries could be improved ... and as long as that's cheaper
than implementing threads, then - personally - I'd need to see more
powerful reasons for threads.

Luckily, I have no say in the development of PHP, so I won't get in
anyone's way should they choose to implement threads :)


-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-25 Thread Peter Lind
On 25 March 2010 20:59, Tommy Pham tommy...@gmail.com wrote:
 On Thu, Mar 25, 2010 at 12:28 PM, Peter Lind peter.e.l...@gmail.com wrote:
 On 25 March 2010 20:19, Tommy Pham tommy...@gmail.com wrote:
 Aren't all feature requests must be analyzed the same way?  Example,
 namespace, how many of us actually uses it now when there is an
 alternative solution- subfolders - that we've been using since who
 knows how long.  I don't know if threads was asked a feature prior
 namespace was implemented.


 Yes, you're right. But feature requests are not equal: some present a
 bigger payoff than others, and some will be more problematic to
 implement than others. If a given language can solve the problems it
 meets based on it's current structure, should you necessarily
 implement new shiny features, that may present problems?

 I'm not against threads in PHP per se ... I just haven't seen a very
 convincing reason for them yet, which is why I'm not very positive
 about the thing. The DB scenario could be handled without threads and
 current libraries could be improved ... and as long as that's cheaper
 than implementing threads, then - personally - I'd need to see more
 powerful reasons for threads.

 Luckily, I have no say in the development of PHP, so I won't get in
 anyone's way should they choose to implement threads :)



 Here's my analysis, let's say that you have 1000 requests / second on
 the web server.  Each request has multiqueries which take a total of 1
 second to complete.  In that one second, how many of those 1000 arrive
 at the same time (that one instant of micro/nano second)?  You see how
 threads come in?  If you have threads that are able finish the
 requests that come in that instant and able to complete them before
 the next batch of requests in that same second, wouldn't you agree
 then that you're delivering faster response time to all your users?


That sounds like your webserver spawning new processes dealing with
requests ... possibly combined with connection pooling and
asynchronous queries and load balancing, etc, etc. So no, I'm not
convinced that PHP with threads would actually deliver much faster
than a properly built setup that makes good usage of technology you'll
have to use anyway.

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-25 Thread Peter Lind
On 25 March 2010 22:51, Lester Caine les...@lsces.co.uk wrote:
 Per Jessen wrote:

 Tommy Pham wrote:

 I'm presenting the argument for threading.  Per is presenting the work
 around using asynchronous queries via mysqlnd.  I did read that link a
 few days ago, Although the user can send multiple queries at once,
 multiple queries cannot be sent over a busy connection. If a query is
 sent while the connection is busy, it waits until the last query is
 finished and discards all its results.  Which sounds like threads -
 multiple connections to not run into that problem.

 You must have read the wrong page.  This is NOT about multiple queries,
 it's about _asynchronous_ queries.

 The only problem here is what the database client can handle. If it can only
 handle one active query, then that is all that can be used. It can be
 started asynchronously and then you come back to pick up the results later,
 and so you can be formating the page ready to insert the results. PDO
 requires that you start a different connection in a different transaction
 for each of these queries, but that is another hot potato. Running 10
 asynchronous queries would require 10 connections as that is how the
 database end works. Adding threading to PHP is going to make no difference?

Actually, this sounds very close to having 10 threads each opening a
connection to the database and running the query ... which was the
solution to the scenario presented, if memory serves.

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-25 Thread Peter Lind
On 25 March 2010 23:23, Tommy Pham tommy...@gmail.com wrote:

 There's the code example from that same link.  You may have executed
 the queries asynchronously, but the process of the results are still
 serial.  Let's face it, all of our processing of queries are not a
 simple echo.  We iterate/loop through the results and display them in
 the desired format.  Having execute the query and the processing of
 the result in threads/parallel, you get the real performance boost
 which I've been trying to convey the concept of serial versus
 parallel.

Actually, you haven't mentioned the processing as part of what the
threads do until now. I see your point though: if you split that part
off, you might gain some performance, that would otherwise be hard to
get at.
 I wonder though, if the performance is worth it in the tradeoff for
the maintenance nightmare it is when you split out content processing
between 10 different threads. I wouldn't personally touch it unless I
had no other option, but that's just my opinion.

Anyway, I don't think either of us will change point of view much at
this point - so we should probably just give the mailing list a rest
by now. Thanks for the posts, it's been interesting to read :)

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] PHP to access shell script to print barcodes

2010-03-24 Thread Peter Lind
The problem you're getting is that your web-server interprets the
request as a request for a normal file and just sends it - in effect,
you're not outputting the postscript file, you're just sending the
.php file. Normally, you'll only get your php executed if the file
requested is a .php or .phtml - unless you've changed your server
config.

Try creating a serveps.php that uses the header(Content-Disposition:
attachment; filename: 'serveps.ps') instead, see if that helps you.

Regards

On 24 March 2010 06:09, Rob Gould gould...@me.com wrote:
 Well, that did something, and it does sound like it should work.  I've 
 scoured the web and haven't found anyone with code that does what I'm trying 
 to do.

 I've got a working, hardcoded Postscript file here:

 http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps

 But I need to somehow serve it with PHP, so I can change some variables in it.

 By putting headers in place with PHP, and then doing an echo of the 
 postscript, I get postscript errors (though Preview doesn't tell me what the 
 error is):

 http://www.winecarepro.com/kiosk/fast/shell/serverps.ps

 Trying to trick the web-browser into thinking it's receiving Postscript from 
 a PHP file is tricky.  I don't know what to do next.

 Here's the code I was using in the above url:  
 http://www.winecarepro.com/kiosk/fast/shell/serveps.php.zip

 It's not clear to me if the server is parsing the postscript first and then 
 serving it, or if the server is server the postscript as-is and the browser 
 sends it to Preview which interprets it.

 I basically want to replicate the functionality found here:

 http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/



 On Mar 23, 2010, at 5:37 PM, Peter Lind wrote:

 You can create a .php script that sets a proper header to make the
 browser download the file rather than display it. That also allows you
 to set the filename for the download. What you'd need to do is include
 something like:

 header(Content-Disposition: attachment; filename: 'barcodemerge.ps');

 That tells the browser to download the file. You can also try setting
 the content-type

 header('Content-type: application/postscript');

 Either of the above might do the trick for you.

 Regards
 Peter

 On 23 March 2010 22:10, Rob Gould gould...@me.com wrote:
 I love the idea of using PHP to insert data into Postscript.  I'm just not 
 sure how to make it happen.

 The good news is that I've got barcodes drawing just the way I need them:

 http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps

 The bad news is that's all hard-coded Postscript.  I'd like to take your 
 suggestion and use PHP to loop-through and draw the barcodes - - - however, 
 if I put anything that resembles PHP in my .ps file, bad things happen.

 Anyone know the secret to creating a postscript .ps file that had PHP code 
 injecting data into it?

 Here's the source file that works.  Where PHP would be handy is at the very 
 bottom of the script

 http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps.zip


 On Mar 23, 2010, at 7:48 AM, Richard Quadling wrote:

 On 23 March 2010 05:48, Jochem Maas joc...@iamjochem.com wrote:
 Op 3/23/10 3:27 AM, Rob Gould schreef:
 I am trying to replicate the functionality that I see on this site:

 http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/

 Notice after you hit SUBMIT QUERY, you get a PDF file with a page of 
 barcodes.  That's _exactly_ what I'm after.
 Fortunately, the author gives step-by-step instructions on how to do 
 this on this page:

 http://blog.maniac.nl/2008/05/28/creating-lto-barcodes/


 So I've gotten through all the steps, and have created the 
 barcode_with_samples.ps file, and have it hosted here:

 http://www.winecarepro.com/kiosk/fast/shell/

 Notice how the last few lines contain the shell-script that renders the 
 postscript:

 #!/bin/bash

 BASE=”100″;
 NR=$BASE

 for hor in 30 220 410
 do
 ver=740
 while [ $ver -ge 40 ];
 do
 printf -v FNR “(%06dL3)” $NR
 echo “$hor $ver moveto $FNR (includetext height=0.55) code39 barcode”
 let ver=$ver-70
 let NR=NR+1
 done
 done


 I need to somehow create a PHP script that executes this shell script. 
  And after doing some research, it sounds like
 I need to use the PHP exec command, so I do that with the following file:

 http://www.winecarepro.com/kiosk/fast/shell/printbarcodes.php

 Which has the following script:

 ?php

 $command=http://www.winecarepro.com/kiosk/fast/shell/barcode_with_sample.ps;;
 exec($command, $arr);

 echo $arr;

 ?


 And, as you can see, nothing works.  I guess firstly, I'd like to know:

 A)  Is this PHP exec call really the way to go with executing this shell 
 script?  Is there a better way?  It seems to me like it's not really 
 executing.

 that's what exec() is for. $command need to contain a *local* path to the 
 command in question, currently your
 trying to pass a url to bash ... which obviously doesn't do much.

 the shell script in question needs to have

Re: [PHP] Will PHP ever grow up and have threading?

2010-03-24 Thread Peter Lind
On 24 March 2010 10:38, Rene Veerman rene7...@gmail.com wrote:
 and if threading and shared memory aren't implemented, then hey, the
 php dev team can build something else in that these naysayers DO need
 eh...

 lol...

Do you have any idea how sad and pathetic you come across? I'm very
sorry to say this, but really, now's the time to stop posting and step
back, take a deep breath, then focus on something else.

 On Wed, Mar 24, 2010 at 11:36 AM, Rene Veerman rene7...@gmail.com wrote:
 unless the actual php development team would like to weigh in on this
 matter of course.

 yes, i do consider it that important.

 these nay-sayers usually also lobby the dev-team to such extent that
 these features would actually not make it into php.

 On Wed, Mar 24, 2010 at 11:31 AM, Rene Veerman rene7...@gmail.com wrote:
 php is not a hammer, its a programming language.

 one that i feel needs to stay ahead of the computing trend if it is to
 be considered a language for large scale applications.

 but you nay-sayers here have convinced me; i'll be shopping for
 another language with which to serve my applications and the weboutput
 they produce..

 thanks for opening my eyes and telling to abandon ship in time.


 On Wed, Mar 24, 2010 at 11:22 AM, Stuart Dallas stut...@gmail.com wrote:
 Heh, you guys are funny!

 On 24 Mar 2010, at 08:58, Rene Veerman wrote:

 On Wed, Mar 24, 2010 at 10:47 AM, Per Jessen p...@computer.org wrote:
 Rene Veerman wrote:

 popular : facebook youtube etc


 Rene, I must be missing something here.  That sort of size implies
 millions in advertising revenue, so why are we discussing how much
 performance we can squeeze out of a single box?  I mean, I'm all for
 efficient use of system resources, but if I have a semi-scalable
 application, it's a lot easier just getting another box than trying to
 change the implementation language.  OTOH, if my design is not
 scalable, it's probably also easier to redo it than trying to change
 the implementation language.

 again:
 a) you're determining the contents of my toolset, without it affecting
 you at all. the way you want it php will degrade into a toy language.

 And how exactly are you defining a toy language? If you want features like 
 threading, why not switch to a language that already supports it?

 b) i will aim for all possible decreases in development time and
 operating costs during, not only in the grow phase but also in hard
 economic times. any business person knows why.

 Yup, this is very good practice, but deciding that one particular tool is 
 the only option is a fatal business decision. Use the right tool for the 
 job!

 What you're trying to do here is akin to taking a hammer and whittling a 
 screwdriver in to the handle. It's ridiculously inefficient, and imo, 
 pretty stupid.

 and you're still trying to impose a toolset on me.

 I didn't think I was - you're the one who seem to be fixed on PHP as the
 only solution, and advocating that it be enhanced to suit your
 purposes.

 no, php is just my toolset of choice, and i think it should grow with
 the times and support threading and shared memory.
 maybe even a few cool features to enable use-as-a-cloud.

 PHP is a hammer, and a bloody good one at that, but you seem to want it to 
 be a tool shed. Accept that it's a hammer, go visit a DIY store, find the 
 right tool for the job and get on with your life!

 The fact is that even if we all agree that PHP needs threading, and one or 
 more people start working on putting it into the core, it will likely be 
 many months before you see any sight of a working version, and even longer 
 before you see a stable release.

 -Stuart

 --
 http://stut.net/



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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-24 Thread Peter Lind
On 24 March 2010 11:53, Tommy Pham tommy...@gmail.com wrote:
 On Wed, Mar 24, 2010 at 3:44 AM, Per Jessen p...@computer.org wrote:
 Tommy Pham wrote:

 On Wed, Mar 24, 2010 at 3:20 AM, Per Jessen p...@computer.org wrote:
 Tommy Pham wrote:

 What I find funny is that one of opponents of PHP threads earlier
 mentioned that how silly it would be to be using C in a web app.
 Now I hear people mentioning C when they need productivity or
 speed...


 I think I was the one to mention the latter, but as I started out
 saying, and as others have said too, it's about the right tool for
 the right job.  When choosing a tool, there are a number of factors
 to consider - developer productivity, available skills, future
 maintenance, performance, scalability, portability, parallelism,
 performance etcetera.


 Funny you should mention all that.  Let's say that you're longer with
 that company, either by direct employment or contract consultant.
 You've implemented C because you need 'thread'.  Now your replacement
 comes in and has no clue about C even though your replacement is a PHP
 guru.  How much headache is maintenance gonna be?  Scalability?
 Portability? wow

 Who was the idi... who hired someone who wasn't suited for the job?
 Tommy, that's a moot argument.  You can't fit a square peg in a round
 hole.



 --
 Per Jessen, Zürich (12.5°C)



 Suited for the job?  You mean introduce more complexity to a problem
 that what could be avoided to begin with if PHP has thread support?
 hmmm

Except, you already introduced complexity into the problem. You see,
working with threads is another requirement, whether it be done in PHP
or not. Hence, hiring the right guy is independent of whether you have
threads in PHP or not - your problem is no less nor no more complex
whether you do threading inside or outside PHP. You just assume that
adding thread support to PHP will solve the problem, but there's no
actual basis to believe this.


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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-24 Thread Peter Lind
On 24 March 2010 12:04, Tommy Pham tommy...@gmail.com wrote:
 On Wed, Mar 24, 2010 at 3:52 AM, Lester Caine les...@lsces.co.uk wrote:
 Tommy Pham wrote:

 How exactly will threading in PHP help with the size of the database?
 That makes no sense to me, please help me understand how you think 
 threading
 will help in this scenario.

 Looking at my example, not just the rows  There are other features
 that require queries to a DB for simple request of a category by a
 shopper,  instead of running those queries in series, running them in
 parallel would yield better response time.

 Database size issues are tackled with clustering, caching and DB
 optimisation. Threading in the language accessing the DB has no advantage
 here.

 Yes, it does.  As mentioned several times, instead of running the
 queries in series, run them in parallel.  If each of the queries takes
 about .05 to .15 seconds.  How long would it take to run them in
 serial?  How long do you it take to run them in parallel?

 Any you have a database that can actually handle that?
 If the database is taking 0.1 seconds per query, and you have 10 queries,
 then getting the data is going to take 1 second to generate. If you want
 some slow query to be started, and come back for the data later, then I
 thought we already had that? But again this is part of the database driver
 anyway. No need to add threading to PHP to get the database connection to
 pull data in the most efficient way. And one does not write the driver in
 PHP? We are using C there already?

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



 Exactly my point.  10 queries taking .1 second each running in serial
 is 1 second total.  How long would it take to run all those same
 queries simultaneously??? What's so difficult about the concept of
 serial vs parallel?

Hmm, just wondering, but how long do you think it will take your
high-traffic site to buckle under the load of the database queries you
want to execute when now you want all of them to execute at the same
time? Going with the 10 queries of .1 second each ... how far do you
think you can scale that before you overload your database server? I'm
just wondering here, I could be completely off the bat.

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-24 Thread Peter Lind
On 24 March 2010 12:14, Tommy Pham tommy...@gmail.com wrote:
 On Wed, Mar 24, 2010 at 4:09 AM, Peter Lind peter.e.l...@gmail.com wrote:
 On 24 March 2010 12:04, Tommy Pham tommy...@gmail.com wrote:
 On Wed, Mar 24, 2010 at 3:52 AM, Lester Caine les...@lsces.co.uk wrote:
 Tommy Pham wrote:

 How exactly will threading in PHP help with the size of the database?
 That makes no sense to me, please help me understand how you think 
 threading
 will help in this scenario.

 Looking at my example, not just the rows  There are other features
 that require queries to a DB for simple request of a category by a
 shopper,  instead of running those queries in series, running them in
 parallel would yield better response time.

 Database size issues are tackled with clustering, caching and DB
 optimisation. Threading in the language accessing the DB has no advantage
 here.

 Yes, it does.  As mentioned several times, instead of running the
 queries in series, run them in parallel.  If each of the queries takes
 about .05 to .15 seconds.  How long would it take to run them in
 serial?  How long do you it take to run them in parallel?

 Any you have a database that can actually handle that?
 If the database is taking 0.1 seconds per query, and you have 10 queries,
 then getting the data is going to take 1 second to generate. If you want
 some slow query to be started, and come back for the data later, then I
 thought we already had that? But again this is part of the database driver
 anyway. No need to add threading to PHP to get the database connection to
 pull data in the most efficient way. And one does not write the driver in
 PHP? We are using C there already?

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



 Exactly my point.  10 queries taking .1 second each running in serial
 is 1 second total.  How long would it take to run all those same
 queries simultaneously??? What's so difficult about the concept of
 serial vs parallel?

 Hmm, just wondering, but how long do you think it will take your
 high-traffic site to buckle under the load of the database queries you
 want to execute when now you want all of them to execute at the same
 time? Going with the 10 queries of .1 second each ... how far do you
 think you can scale that before you overload your database server? I'm
 just wondering here, I could be completely off the bat.

 IIRC, one of opponents of PHP thread mention load balancer/cluster or
 another opponent mention 'throw money into the hardware problem'

Yes. If you can accept that solution for this problem, why not for the
other problem?

Please keep in mind that I'm not for or against threads in PHP. I
think they can solve some problems and I think they'll create a host
of others - currently I have no idea if the benefits would outweigh
the costs.

I just have a huge problem understanding why alternative solutions to
problems are thrown out with No! That won't work when they haven't
been shown to be problematic. So far, we've seen no examples of
situations where PHP would be the best choice of language and would
need threads to solve the problem at hand.

Assuming that you have a right to use a threaded version of PHP
amounts to walking into your favourite tool-store and demanding that
you get a hammer that doubles as a phone. And when none are available,
you start yelling at other customers for suggesting the use of a phone
and hammer in combination.


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





 --
 hype
 WWW: http://plphp.dk / http://plind.dk
 LinkedIn: http://www.linkedin.com/in/plind
 Flickr: http://www.flickr.com/photos/fake51
 BeWelcome: Fake51
 Couchsurfing: Fake51
 /hype





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Properly handling multiple constructors.

2010-03-24 Thread Peter Lind
Hmmm, that looks to me like you're trying to solve a problem in PHP
with a c/c++c/# overloading solution. I'd give the builder pattern a
try instead: http://en.wikipedia.org/wiki/Builder_pattern

On 24 March 2010 13:01, Richard Quadling rquadl...@googlemail.com wrote:
 Hi.

 I have a scenario where I would _like_ to have multiple constructors
 for a class.

 Each constructor has a greater number of parameters than the previous one.

 e.g.

 ?php
 class myClass {
 __construct(string $Key) // use key to get the complex details.
 __construct(string $Part1, string $Part2, string $Part3) //
 Alternative route to the complex details.
 __construct(array $Complex) // All the details
 }

 Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2
 and 3 are the main details and well documented defaults for the rest
 of the rules. Complex is all the rules.

 Each constructor will end up with all the parts being known ($Key,
 $Part1, $Part2, $Part3, $Complex).

 But, PHP doesn't support multiple constructors.

 Initially I thought about this ...

 __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null)

 But then documenting the first param as being 1 of three different
 meanings is pretty much a no go.

 So I'm looking for a clean and easily understood way to provide this.

 I won't be the only user of the code and not everyone has the same
 knowledge level, hence a mechanism that is easily documentable.

 I think I may need a factory with multiple methods (FactoryKey,
 FactoryPart1To3, FactoryComplex). Make the factory a static/singleton.
 All these methods eventually call the real class with the complex
 rule.

 Is that obvious enough?

 Regards,

 Richard.


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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Properly handling multiple constructors.

2010-03-24 Thread Peter Lind
And how exactly does that differ from building the same pizza in
different ways? Builder doesn't mean you have to create different
objects, it means taking the complexity in building a given object or
set of objects and storing it in one place.

In your case, it allows you to build your object in different ways
while documenting it properly and avoid the huge switch inside your
constructor that Nilesh proposed.

On 24 March 2010 13:35, Richard Quadling rquadl...@googlemail.com wrote:
 On 24 March 2010 12:06, Peter Lind peter.e.l...@gmail.com wrote:
 Hmmm, that looks to me like you're trying to solve a problem in PHP
 with a c/c++c/# overloading solution. I'd give the builder pattern a
 try instead: http://en.wikipedia.org/wiki/Builder_pattern

 On 24 March 2010 13:01, Richard Quadling rquadl...@googlemail.com wrote:
 Hi.

 I have a scenario where I would _like_ to have multiple constructors
 for a class.

 Each constructor has a greater number of parameters than the previous one.

 e.g.

 ?php
 class myClass {
 __construct(string $Key) // use key to get the complex details.
 __construct(string $Part1, string $Part2, string $Part3) //
 Alternative route to the complex details.
 __construct(array $Complex) // All the details
 }

 Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2
 and 3 are the main details and well documented defaults for the rest
 of the rules. Complex is all the rules.

 Each constructor will end up with all the parts being known ($Key,
 $Part1, $Part2, $Part3, $Complex).

 But, PHP doesn't support multiple constructors.

 Initially I thought about this ...

 __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null)

 But then documenting the first param as being 1 of three different
 meanings is pretty much a no go.

 So I'm looking for a clean and easily understood way to provide this.

 I won't be the only user of the code and not everyone has the same
 knowledge level, hence a mechanism that is easily documentable.

 I think I may need a factory with multiple methods (FactoryKey,
 FactoryPart1To3, FactoryComplex). Make the factory a static/singleton.
 All these methods eventually call the real class with the complex
 rule.

 Is that obvious enough?

 Regards,

 Richard.


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





 --
 hype
 WWW: http://plphp.dk / http://plind.dk
 LinkedIn: http://www.linkedin.com/in/plind
 Flickr: http://www.flickr.com/photos/fake51
 BeWelcome: Fake51
 Couchsurfing: Fake51
 /hype


 I'm not building different types of pizza. Just the same pizza via
 different routes.

 Along the lines of ...

 Pizza = new Pizza('MyFavouritePizza') // A ham+pineapple+cheese pizza.
 Pizza = new Pizza('ham', 'pineapple', 'cheese'); // A generic
 ham+pineapple+cheese pizza
 Pizza = new Pizza(array('base' = 'thin', 'toppings' = array('ham',
 'pineapple'), 'cheese'=true)); // A complex description.

 I suppose the interfaces are beginner, intermediate and advanced, but
 ultimately all generate identical objects.

 Richard.

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




-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Properly handling multiple constructors.

2010-03-24 Thread Peter Lind
One of the main points of the OP was that you can document the code
properly. Your example doesn't allow for nice docblocks in any way, as
you'll either have to param points or a whole lot of noise.

Quick note: __ prefixed functions are reserved, you shouldn't use
that prefix for any of your own functions. However unlikely it is that
PHP will ever have a __construct_bluh() function ...

On 24 March 2010 15:22, Robert Cummings rob...@interjinn.com wrote:
 Robert Cummings wrote:

 Richard Quadling wrote:

 Hi.

 I have a scenario where I would _like_ to have multiple constructors
 for a class.

 Each constructor has a greater number of parameters than the previous
 one.

 e.g.

 ?php
 class myClass {
 __construct(string $Key) // use key to get the complex details.
 __construct(string $Part1, string $Part2, string $Part3) //
 Alternative route to the complex details.
 __construct(array $Complex) // All the details
 }

 Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2
 and 3 are the main details and well documented defaults for the rest
 of the rules. Complex is all the rules.

 Each constructor will end up with all the parts being known ($Key,
 $Part1, $Part2, $Part3, $Complex).

 But, PHP doesn't support multiple constructors.

 Initially I thought about this ...

 __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null)

 But then documenting the first param as being 1 of three different
 meanings is pretty much a no go.

 So I'm looking for a clean and easily understood way to provide this.

 I won't be the only user of the code and not everyone has the same
 knowledge level, hence a mechanism that is easily documentable.

 I think I may need a factory with multiple methods (FactoryKey,
 FactoryPart1To3, FactoryComplex). Make the factory a static/singleton.
 All these methods eventually call the real class with the complex
 rule.

 Is that obvious enough?

 Factory method is probably the cleanest and simplest solution. Just pass
 an ID as the first parameter to the real constructor and then it can route
 to the appropriate behaviour:

 Here's a better example (tested):

 ?php

 class Foo
 {
    const CONSTRUCT_BLAH = 1;
    const CONSTRUCT_BLEH = 2;
    const CONSTRUCT_BLUH = 3;

    function __construct( $constructId )
    {
        static $map = array
        (
            self::CONSTRUCT_BLAH = '__construct_blah',
            self::CONSTRUCT_BLEH = '__construct_bleh',
            self::CONSTRUCT_BLUH = '__construct_bluh',
        );

        $obj = null;

        if( isset( $map[$constructId] ) )
        {
            $args = func_get_args();
            $args = array_shift( $args );

            call_user_func_array(
                array( 'self', $map[$constructId] ), $args );
        }
        else
        {
            // Generate an error or exception.
        }
    }

    static function __construct_bleh( $arg1 )
    {
        echo Called: .__FUNCTION__.( $arg1 )\n;
    }

    static function __construct_blah( $arg1 )
    {
        echo Called: .__FUNCTION__.( $arg1 )\n;
    }

    static function __construct_bluh( $arg1 )
    {
        echo Called: .__FUNCTION__.( $arg1 )\n;
    }

    static function getBlah( $arg1 )
    {
        return new Foo( self::CONSTRUCT_BLAH, $arg1 );
    }

    static function getBleh( $arg1 )
    {
        return new Foo( self::CONSTRUCT_BLEH, $arg1 );
    }

    static function getBluh( $arg1 )
    {
        return new Foo( self::CONSTRUCT_BLUH, $arg1 );
    }
 }

 $obj = Foo::getBlah( 'blah' );
 $obj = Foo::getBleh( 'bleh' );
 $obj = Foo::getBluh( 'bluh' );

 ?

 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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Properly handling multiple constructors.

2010-03-24 Thread Peter Lind
On 24 March 2010 15:33, Robert Cummings rob...@interjinn.com wrote:
 Peter Lind wrote:

 One of the main points of the OP was that you can document the code
 properly. Your example doesn't allow for nice docblocks in any way, as
 you'll either have to param points or a whole lot of noise.

 I dunno, seems highly documentable to me. Each route is handled by it's own
 method with the parameters being fully declared in the handler method's
 signature.

Only problem is the OP wanted to be able to created objects with
variable amounts of arguments. I.e. passing just one argument to the
constructor wasn't an option, far as I could tell. That's why he was
looking at c++/c# overloading: creating a constructor for each
scenario because the amount and kind of arguments varied.

Which means that the docblock for your constructor will look something like

/**
 * dynamic constructor
 *
 * @param int $constructor_type
 * @param string|array|object|whatever_you_could_think_to_throw_at_it $something
 * @param string|array|object|whatever_you_could_think_to_throw_at_it
$something this is optional
 * @param etc
 *
 * @access public
 * @return void
 */
 Quick note: __ prefixed functions are reserved, you shouldn't use
 that prefix for any of your own functions. However unlikely it is that
 PHP will ever have a __construct_bluh() function ...

 Yeah, I know... I threw caution to the wind in this quick example. But for
 the sake of archives and newbies reading them, I shouldn't have :)

 Cheers,
 Rob.



 On 24 March 2010 15:22, Robert Cummings rob...@interjinn.com wrote:

 Robert Cummings wrote:

 Richard Quadling wrote:

 Hi.

 I have a scenario where I would _like_ to have multiple constructors
 for a class.

 Each constructor has a greater number of parameters than the previous
 one.

 e.g.

 ?php
 class myClass {
 __construct(string $Key) // use key to get the complex details.
 __construct(string $Part1, string $Part2, string $Part3) //
 Alternative route to the complex details.
 __construct(array $Complex) // All the details
 }

 Essentially, SimpleKey is a key to a set of predefined rules. Part1, 2
 and 3 are the main details and well documented defaults for the rest
 of the rules. Complex is all the rules.

 Each constructor will end up with all the parts being known ($Key,
 $Part1, $Part2, $Part3, $Complex).

 But, PHP doesn't support multiple constructors.

 Initially I thought about this ...

 __construct($Key_Part1_Complex, $Part2=Null, $Part3=Null)

 But then documenting the first param as being 1 of three different
 meanings is pretty much a no go.

 So I'm looking for a clean and easily understood way to provide this.

 I won't be the only user of the code and not everyone has the same
 knowledge level, hence a mechanism that is easily documentable.

 I think I may need a factory with multiple methods (FactoryKey,
 FactoryPart1To3, FactoryComplex). Make the factory a static/singleton.
 All these methods eventually call the real class with the complex
 rule.

 Is that obvious enough?

 Factory method is probably the cleanest and simplest solution. Just pass
 an ID as the first parameter to the real constructor and then it can
 route
 to the appropriate behaviour:

 Here's a better example (tested):

 ?php

 class Foo
 {
   const CONSTRUCT_BLAH = 1;
   const CONSTRUCT_BLEH = 2;
   const CONSTRUCT_BLUH = 3;

   function __construct( $constructId )
   {
       static $map = array
       (
           self::CONSTRUCT_BLAH = '__construct_blah',
           self::CONSTRUCT_BLEH = '__construct_bleh',
           self::CONSTRUCT_BLUH = '__construct_bluh',
       );

       $obj = null;

       if( isset( $map[$constructId] ) )
       {
           $args = func_get_args();
           $args = array_shift( $args );

           call_user_func_array(
               array( 'self', $map[$constructId] ), $args );
       }
       else
       {
           // Generate an error or exception.
       }
   }

   static function __construct_bleh( $arg1 )
   {
       echo Called: .__FUNCTION__.( $arg1 )\n;
   }

   static function __construct_blah( $arg1 )
   {
       echo Called: .__FUNCTION__.( $arg1 )\n;
   }

   static function __construct_bluh( $arg1 )
   {
       echo Called: .__FUNCTION__.( $arg1 )\n;
   }

   static function getBlah( $arg1 )
   {
       return new Foo( self::CONSTRUCT_BLAH, $arg1 );
   }

   static function getBleh( $arg1 )
   {
       return new Foo( self::CONSTRUCT_BLEH, $arg1 );
   }

   static function getBluh( $arg1 )
   {
       return new Foo( self::CONSTRUCT_BLUH, $arg1 );
   }
 }

 $obj = Foo::getBlah( 'blah' );
 $obj = Foo::getBleh( 'bleh' );
 $obj = Foo::getBluh( 'bluh' );

 ?

 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






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




-- 
hype
WWW: http://plphp.dk / http://plind.dk

Re: [PHP] Properly handling multiple constructors.

2010-03-24 Thread Peter Lind
On 24 March 2010 16:09, Robert Cummings rob...@interjinn.com wrote:


 Peter Lind wrote:

 On 24 March 2010 15:33, Robert Cummings rob...@interjinn.com wrote:

 Peter Lind wrote:

 One of the main points of the OP was that you can document the code
 properly. Your example doesn't allow for nice docblocks in any way, as
 you'll either have to param points or a whole lot of noise.

 I dunno, seems highly documentable to me. Each route is handled by it's
 own
 method with the parameters being fully declared in the handler method's
 signature.

 Only problem is the OP wanted to be able to created objects with
 variable amounts of arguments. I.e. passing just one argument to the
 constructor wasn't an option, far as I could tell. That's why he was
 looking at c++/c# overloading: creating a constructor for each
 scenario because the amount and kind of arguments varied.

 Which means that the docblock for your constructor will look something
 like

 /**
  * dynamic constructor
  *
  * @param int $constructor_type
  * @param string|array|object|whatever_you_could_think_to_throw_at_it
 $something
  * @param string|array|object|whatever_you_could_think_to_throw_at_it
 $something this is optional
  * @param etc
  *
  * @access public
  * @return void
  */

 Actually, I would write it more like the following:

 /**
  * dynamic constructor that delegates construction and parameters to a
  * registered alternate constructor. See specific constructors for
  * supported parameters.
  *
  * @param int $constructor_type
  * @param mixed $param,
  *
  * @access public
  * @return void
  */

 The ,... is a supported syntax. Then I'd add the appropriate docblock for
 the alternate constructors.

It might be but in effect the documentation you're left with is vague
and has double the amount of documentation lookups, to find out which
parameters you can pass. Using a separate object to create the one you
want avoids this.

However, which solution fits the problem best is determined by the
angle you're looking from. If you want to avoid extra classes, having
a constructor like you're supposing is probably the best idea.

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




-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Properly handling multiple constructors.

2010-03-24 Thread Peter Lind
On 24 March 2010 16:23, Robert Cummings rob...@interjinn.com wrote:
 Peter Lind wrote:

 On 24 March 2010 16:09, Robert Cummings rob...@interjinn.com wrote:

 Peter Lind wrote:

 On 24 March 2010 15:33, Robert Cummings rob...@interjinn.com wrote:

 Peter Lind wrote:

 One of the main points of the OP was that you can document the code
 properly. Your example doesn't allow for nice docblocks in any way, as
 you'll either have to param points or a whole lot of noise.

 I dunno, seems highly documentable to me. Each route is handled by it's
 own
 method with the parameters being fully declared in the handler method's
 signature.

 Only problem is the OP wanted to be able to created objects with
 variable amounts of arguments. I.e. passing just one argument to the
 constructor wasn't an option, far as I could tell. That's why he was
 looking at c++/c# overloading: creating a constructor for each
 scenario because the amount and kind of arguments varied.

 Which means that the docblock for your constructor will look something
 like

 /**
  * dynamic constructor
  *
  * @param int $constructor_type
  * @param string|array|object|whatever_you_could_think_to_throw_at_it
 $something
  * @param string|array|object|whatever_you_could_think_to_throw_at_it
 $something this is optional
  * @param etc
  *
  * @access public
  * @return void
  */

 Actually, I would write it more like the following:

 /**
  * dynamic constructor that delegates construction and parameters to a
  * registered alternate constructor. See specific constructors for
  * supported parameters.
  *
  * @param int $constructor_type
  * @param mixed $param,
  *
  * @access public
  * @return void
  */

 The ,... is a supported syntax. Then I'd add the appropriate docblock for
 the alternate constructors.

 It might be but in effect the documentation you're left with is vague
 and has double the amount of documentation lookups, to find out which
 parameters you can pass. Using a separate object to create the one you
 want avoids this.

 But then you need to keep track of many different classes/objects rather
 than a single. You also run into confusion as to what the difference is when
 really they are the same, just built differently. In this context you have
 even more document points to review since you must read the class
 information in addition to the method signature. Also using a separate class
 just to facilitate a different constructor seems abusive of class semantics
 since the objects are intended to be identical, just built differently. I
 would find this more unwieldy to deal with in an environement than just
 viewing the alternate methods.

Yes, you have to keep track of two different objects instead of one.
Managing complexity by delegating responsibility is normally a good
thing. And no, there is no confusion: you're building the same object
in different ways, so you're getting the same object, not one that
merely looks the same. As for abusing class semantics ... I don't see
it. Using separate classes for different things is what OOP is about.
If your constructor is trying to do 15 different things you're
designing it wrong - methods shouldn't have to rely upon massive
switches or the equivalent done using foreach loops and arrays.
 As for more documentation: You'd have two class docblocks plus a
docblock for each build method, so I suppose you're right, that is one
extra docblock.

 However, which solution fits the problem best is determined by the
 angle you're looking from. If you want to avoid extra classes, having
 a constructor like you're supposing is probably the best idea.

 Extra classes is also more code, probably more files (if you put them in
 separate files), more points of management.

Yes. What does your code look like? One big file containing everything?

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




-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Properly handling multiple constructors.

2010-03-24 Thread Peter Lind
On 24 March 2010 16:48, Robert Cummings rob...@interjinn.com wrote:
 Peter Lind wrote:

 The ,... is a supported syntax. Then I'd add the appropriate docblock
 for
 the alternate constructors.

 It might be but in effect the documentation you're left with is vague
 and has double the amount of documentation lookups, to find out which
 parameters you can pass. Using a separate object to create the one you
 want avoids this.



 But then you need to keep track of many different classes/objects rather
 than a single. You also run into confusion as to what the difference is
 when
 really they are the same, just built differently. In this context you
 have
 even more document points to review since you must read the class
 information in addition to the method signature. Also using a separate
 class
 just to facilitate a different constructor seems abusive of class
 semantics
 since the objects are intended to be identical, just built differently. I
 would find this more unwieldy to deal with in an environement than just
 viewing the alternate methods.

 Yes, you have to keep track of two different objects instead of one.
 Managing complexity by delegating responsibility is normally a good
 thing.

 Absolutely, delegating responsibility to manage complexity is very good. My
 proposed solution does this.

 And no, there is no confusion: you're building the same object
 in different ways, so you're getting the same object, not one that
 merely looks the same.

 No, you're getting different objects. If they come from different classes
 then they are different. Yes they may be subclasses, but the OP indicated
 they differ only by how they are built. Adding 10 different subclasses just
 to facilitate constructor overloading seems egregious, especially if the
 object already has logical subclasses.

As I suspected, you didn't understand what I meant. The builder
pattern lets you build complex objects in steps, separating out
complexity. It's equally well suited to building one object as many
objects and what I had in mind was a simplified builder/factory.

Which means you have:

class ObjectBuilder
class Object

where ObjectBuilder comes with several different ways of building
Object. That's two objects, not the list of objects extending
something you posted.

    class Dog
    class Dog_construct1 extends Dog
    class Dog_construct2 extends Dog
    class Dog_construct3 extends Dog
    class Dog_construct4 extends Dog

    class Dalmation extends Dog
    class Dalmation_construct1 extends Dog_construct1
    class Dalmation_construct2 extends Dog_construct2
    class Dalmation_construct3 extends Dog_construct3
    class Dalmation_construct4 extends Dog_construct4

 But now Dalmation_construct1 isn't related to Dalmation... or do you propose
 the following:

    class Dalmation extends Dalmation
    class Dalmation_construct1 extends Dalmation
    class Dalmation_construct2 extends Dalmation
    class Dalmation_construct3 extends Dalmation
    class Dalmation_construct4 extends Dalmation

 But now Dalmation_construct1 isn't related Dog_construct1. This seems
 problematic from a design perspective unless I'm missing something in your
 proposal.

  As for abusing class semantics ... I don't see

 it. Using separate classes for different things is what OOP is about.
 If your constructor is trying to do 15 different things you're
 designing it wrong - methods shouldn't have to rely upon massive
 switches or the equivalent done using foreach loops and arrays.

 Sorry, switches, foreach, and isset are not equivalent. My approach is O( lg
 n ). Foreach and switches are O( n ) to find a candidate. Additionally, my
 constructor does 1 thing, it delegates to the appropriate constructor which
 does one thing also... builds the object according to intent.

Yes, your constructor does one thing, which is indirectly related to
constructing instead of carrying out the actual constructing. I prefer
constructors to construct something, but that's a matter of preference
I expect.

  As for more documentation: You'd have two class docblocks plus a
 docblock for each build method, so I suppose you're right, that is one
 extra docblock.

 However, which solution fits the problem best is determined by the
 angle you're looking from. If you want to avoid extra classes, having
 a constructor like you're supposing is probably the best idea.

 Extra classes is also more code, probably more files (if you put them in
 separate files), more points of management.

 Yes. What does your code look like? One big file containing everything?

 No, I said probably because I put classes in separate files. I was saying
 there is probably another added maintenance headache of all these new class
 files.

There would be if one were to use your scheme of subclassing. What I
proposed doesn't do that in any way, so there's not much of a
maintenance headache.

Anyway, all this is theoretical seeing as you can equally well use a
set of static methods

Re: [PHP] Filtering all output to STDERR

2010-03-23 Thread Peter Lind
Ahh, I see why my suggestions had no effect - I assumed you were
dealing with normal php errors, not something done customly by the
code.

I'm afraid the only option I see is that of debugging the problem
script to find out where it opens STDERR - if you're certain that the
script specifically outputs messages to STDERR, then it's opening that
stream somewhere before the output.

Regards
Peter

On 23 March 2010 11:28, Marten Lehmann lehm...@cnm.de wrote:
 Have you tried with
 http://dk2.php.net/manual/en/function.error-reporting.php or just the
 @ operator?

 Yes. But this does not work, because error levels and the @ operator only
 relate to errors thrown by the PHP runtime and have nothing to do with
 STDERR.

 But I need a way to close the STDERR file handle at the beginning of a
 script or at least catch and remove all output sent to STDERR.

 Regards
 Marten

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] PHP to access shell script to print barcodes

2010-03-23 Thread Peter Lind
You can create a .php script that sets a proper header to make the
browser download the file rather than display it. That also allows you
to set the filename for the download. What you'd need to do is include
something like:

header(Content-Disposition: attachment; filename: 'barcodemerge.ps');

That tells the browser to download the file. You can also try setting
the content-type

header('Content-type: application/postscript');

Either of the above might do the trick for you.

Regards
Peter

On 23 March 2010 22:10, Rob Gould gould...@me.com wrote:
 I love the idea of using PHP to insert data into Postscript.  I'm just not 
 sure how to make it happen.

 The good news is that I've got barcodes drawing just the way I need them:

 http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps

 The bad news is that's all hard-coded Postscript.  I'd like to take your 
 suggestion and use PHP to loop-through and draw the barcodes - - - however, 
 if I put anything that resembles PHP in my .ps file, bad things happen.

 Anyone know the secret to creating a postscript .ps file that had PHP code 
 injecting data into it?

 Here's the source file that works.  Where PHP would be handy is at the very 
 bottom of the script

 http://www.winecarepro.com/kiosk/fast/shell/barcodemerge.ps.zip


 On Mar 23, 2010, at 7:48 AM, Richard Quadling wrote:

 On 23 March 2010 05:48, Jochem Maas joc...@iamjochem.com wrote:
 Op 3/23/10 3:27 AM, Rob Gould schreef:
 I am trying to replicate the functionality that I see on this site:

 http://blog.maniac.nl/webbased-pdf-lto-barcode-generator/

 Notice after you hit SUBMIT QUERY, you get a PDF file with a page of 
 barcodes.  That's _exactly_ what I'm after.
 Fortunately, the author gives step-by-step instructions on how to do this 
 on this page:

 http://blog.maniac.nl/2008/05/28/creating-lto-barcodes/


 So I've gotten through all the steps, and have created the 
 barcode_with_samples.ps file, and have it hosted here:

 http://www.winecarepro.com/kiosk/fast/shell/

 Notice how the last few lines contain the shell-script that renders the 
 postscript:

 #!/bin/bash

 BASE=”100″;
 NR=$BASE

 for hor in 30 220 410
 do
 ver=740
 while [ $ver -ge 40 ];
 do
 printf -v FNR “(%06dL3)” $NR
 echo “$hor $ver moveto $FNR (includetext height=0.55) code39 barcode”
 let ver=$ver-70
 let NR=NR+1
 done
 done


 I need to somehow create a PHP script that executes this shell script.  
 And after doing some research, it sounds like
 I need to use the PHP exec command, so I do that with the following file:

 http://www.winecarepro.com/kiosk/fast/shell/printbarcodes.php

 Which has the following script:

 ?php

 $command=http://www.winecarepro.com/kiosk/fast/shell/barcode_with_sample.ps;;
 exec($command, $arr);

 echo $arr;

 ?


 And, as you can see, nothing works.  I guess firstly, I'd like to know:

 A)  Is this PHP exec call really the way to go with executing this shell 
 script?  Is there a better way?  It seems to me like it's not really 
 executing.

 that's what exec() is for. $command need to contain a *local* path to the 
 command in question, currently your
 trying to pass a url to bash ... which obviously doesn't do much.

 the shell script in question needs to have the executable bit set in order 
 to run (either that or change to command to
 run bash with your script as an argument)

 I'd also suggest putting the shell script outside of your webroot, or at 
 least in a directory that's not accessable
 from the web.

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



 I think this is a translation of the script to PHP.

 ?php
 $BASE = 100;
 $NR   = $BASE;

 foreach(array(30, 220, 410) as $hor) {
       $ver = 740;
       while ($ver = 40) {
               printf($hor $ver moveto (%06dL3) (includetext height=0.55) 
 code39
 barcode\n, $NR);
               $ver -= 70;
               ++$NR;
       }
 }



 It produces output like ...

 30 740 moveto (000100L3) (includetext height=0.55) code39 barcode
 30 670 moveto (000101L3) (includetext height=0.55) code39 barcode
 30 600 moveto (000102L3) (includetext height=0.55) code39 barcode
 30 530 moveto (000103L3) (includetext height=0.55) code39 barcode
 30 460 moveto (000104L3) (includetext height=0.55) code39 barcode
 30 390 moveto (000105L3) (includetext height=0.55) code39 barcode
 30 320 moveto (000106L3) (includetext height=0.55) code39 barcode
 30 250 moveto (000107L3) (includetext height=0.55) code39 barcode
 30 180 moveto (000108L3) (includetext height=0.55) code39 barcode
 30 110 moveto (000109L3) (includetext height=0.55) code39 barcode
 30 40 moveto (000110L3) (includetext height=0.55) code39 barcode
 220 740 moveto (000111L3) (includetext height=0.55) code39 barcode
 220 670 moveto (000112L3) (includetext height=0.55) code39 barcode
 220 600 moveto (000113L3) (includetext height=0.55) code39 barcode
 220 530 moveto (000114L3) (includetext height=0.55) code39 barcode
 220 460

Re: [PHP] Filtering all output to STDERR

2010-03-22 Thread Peter Lind
You could consider suppressing errors for the duration of the
problematic call - if indeed you're looking at a warning that doesn't
grind everything to a halt.

On 22 March 2010 18:01, Marten Lehmann lehm...@cnm.de wrote:
 Hello,

 we have a strange problem here:

 - Our ISP is merging STDERR and STDOUT to STDOUT
 - We are calling a non-builtin function within PHP 5.2 which includes a lot
 of code and calls a lot of other functions
 - When calling this function, we receive the output Cannot open  on
 STDERR. But since STDERR and STDOUT are merged, this Cannot open  breaks
 the required HTTP-header which needs to be sent first.

 We really tried a lot to find out where this message comes from, we even
 used strace and ran PHP on the command line. But we cannot figure out the
 origin, so all we want to do is to get rid of the output sent to STDERR.

 We tried to close STDERR, but it didn't work out.

 We thought of using ob_start() and ob_end_clean(), but we cannot get it
 working with STDERR. Any ideas?

 Kind regards
 Marten

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Global Var Disappearing After Function

2010-03-22 Thread Peter van der Does
On Mon, 22 Mar 2010 16:58:33 -0400
APseudoUtopia apseudouto...@gmail.com wrote:

 Hey list,
 
 I have a very odd problem which has been driving me crazy for two
 days. I've been trying to debug my code and gave up. I finally coded a
 very simple representation of what the code does, and I get the same
 problem. However, I still don't understand what's causing it.
 
 The representational code:
 http://pastie.org/private/fz3lgvsjopz3dhid8cf9a
 
 As you can see, it's very simple. A variable is set, then a function
 is called which modifies the variable in the global scope. However,
 the modifications CANNOT BE SEEN after the function is called.
 
 The output from the script is here:
 http://pastie.org/private/29r5mrr1k7rtqmw7eyoja
 
 As you can see, the modifications in do_test() cannot be seen after
 the function is called.
 
 What is causing this? And how can I fix it?
 
 Thanks!
 

From PHP.net:

If a globalized variable is unset() inside of a function, only the
local variable is destroyed. The variable in the calling environment
will retain the same value as before unset() was called. [1]

[1] http://php.net/manual/en/function.unset.php


-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



Re: [PHP] Filtering all output to STDERR

2010-03-22 Thread Peter Lind
Have you tried with
http://dk2.php.net/manual/en/function.error-reporting.php or just the
@ operator?

On 22 March 2010 23:56, Marten Lehmann lehm...@cnm.de wrote:
 Hello,

 You could consider suppressing errors for the duration of the
 problematic call

 yes, but how?

 Regards
 Marten

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] no svn checkout of the current PHP development repo?

2010-03-20 Thread Peter Lind
You should probably have a look at the internals list - there's a lot
of discussion going on as to what should happen in terms of SVN
structure.

Regards
Peter

On 20 March 2010 12:32, Robert P. J. Day rpj...@crashcourse.ca wrote:

  just for fun, i figured i'd check out the current PHP development
 stream.  however, if you read the web page here:

  http://php.net/svn.php

 there's no mention of the trunk, simply references to branches such
 as 5.2 and 5.3.

  i popped over to:

  http://svn.php.net/viewvc/php/php-src/

 and, sure enough, there's no trunk directory.  am i just missing
 something?  because if i click on the PHP 6 link up there on the
 right (which represents exactly what i'd expect for the URL of the
 trunk), bad things happen:

  An Exception Has Occurred

  Unknown location: /php/php-src/trunk
  HTTP Response Status

  404 Not Found

 thoughts?  i'll assume this is just a temporary thing but, in any
 event, if the trunk is normally available, the PHP svn page should
 really mention it explicitly, not just the 5.x branches.

 rday
 --

 
 Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

 Web page:                                          http://crashcourse.ca
 Twitter:                                       http://twitter.com/rpjday
 

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] web sniffer

2010-03-19 Thread Peter Lind
You should be able to do that by setting context options:
http://www.php.net/manual/en/context.http.php

On 19 March 2010 08:53, Jochen Schultz jschu...@sportimport.de wrote:
 Btw., when you use file_get_contets, is there a good way to tell the script
 to stop recieving the file after let's say 2 seconds - just in case the
 server is not reachable - to avoid using fsockopen?

 regards
 Jochen

 madunix schrieb:

 okay ..it works now i use
 ?php
 $data=file_get_contents(http://www.my.com;);
 echo $data;
 ?

 On Fri, Mar 19, 2010 at 12:32 AM, Adam Richardson simples...@gmail.com
 wrote:

 On Thu, Mar 18, 2010 at 6:08 PM, Ashley Sheridan
 a...@ashleysheridan.co.uk
 wrote:

 On Fri, 2010-03-19 at 00:11 +0200, madunix wrote:

 trying http://us3.php.net/manual/en/function.fsockopen.php
 do you a piece of code that  read parts  pages.


 On Fri, Mar 19, 2010 at 12:00 AM, Ashley Sheridan
 a...@ashleysheridan.co.uk wrote:


        On Fri, 2010-03-19 at 00:03 +0200, madunix wrote:

         I've been trying to read the contents from a particular URL
 into a
         string in PHP, and can't get it to work.  any help.
        
         Thanks
        
         --
         If there is a way, I will find one...***
         If there is none, I will make one...***
          madunix  **
        




        How have you been trying to do it so far?

        There are a couple of ways. file_get_contents() and fopen()
        will work on URL's if the right ports are open.

        Most usually though cURL is used for this sort of thing.

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







 --
 If there is a way, I will find one...***
 If there is none, I will make one...***
  madunix  **


 I think you're over-complicating things by using fsockopen(). Try one of
 the functions I mentioned in my last email

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


 I agree with Ashley, use one of the other options and then parse the
 response to get the part of the page you'd like to work with.

 --
 Nephtali:  PHP web framework that functions beautifully
 http://nephtaliproject.com





 --
  Sport Import GmbH   - Amtsgericht Oldenburg  - Tel:   +49-4405-9280-63
  Industriestrasse 39 - HRB 1202900            -
  26188 Edewecht      - GF: Michael Müllmann

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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Re: PHP in HTML code

2010-03-19 Thread Peter Lind
On 19 March 2010 10:17, Michael A. Peters mpet...@mac.com wrote:

 I don't care what people do in their code.
 I do not like released code with short tags, it has caused me problems when
 trying to run php webapps that use short tags, I have to go through the code
 and change them.

 So what people do with their private code, I could care less about.
 But if releasing php code for public consumption, I guess I'm a preacher
 asking people to get religion, because short tags do not belong in projects
 that are released to the public. Just like addslashes and magic quotes and
 most html entities should not be used in php code released for public
 consumption.


What he said. Now, could we get over this discussion? It's not exactly
going anywhere.

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Need routine to tell me number of dimensions in array.

2010-03-16 Thread Peter Lind
This is one example where references actually decrease memory usage.
The main reason is the recursive nature of the function. Try

?php

echo memory_get_usage() . PHP_EOL;
$array = range(0,100);
$array[10] = range(0,10);
$array[20] = range(0,10);
$array[30] = range(0,10);
$array[40] = range(0,10);
$array[50] = range(0,10);
$array[60] = range(0,10);
$array[70] = range(0,10);
$array[80] = range(0,10);
$array[90] = range(0,10);
$array[100] = range(0,10);
echo memory_get_usage() . PHP_EOL;
carray($array);
function carray ($array)
{
foreach ($array as $value)
{
if (is_array($value)) carray($value);
}
echo memory_get_usage() . PHP_EOL;
echo count($array) . PHP_EOL;
}
echo memory_get_usage() . PHP_EOL;

And then compare with:

?php

echo memory_get_usage() . PHP_EOL;
$array = range(0,100);
$array[10] = range(0,10);
$array[20] = range(0,10);
$array[30] = range(0,10);
$array[40] = range(0,10);
$array[50] = range(0,10);
$array[60] = range(0,10);
$array[70] = range(0,10);
$array[80] = range(0,10);
$array[90] = range(0,10);
$array[100] = range(0,10);
echo memory_get_usage() . PHP_EOL;
carray($array);
function carray ($array)
{
$i = 0;
foreach ($array as $value)
{
if (is_array($value)) carray($value);
}
echo memory_get_usage() . PHP_EOL;
echo count($array) . PHP_EOL;
}
echo memory_get_usage() . PHP_EOL;

The memory usage spikes in the first example when you hit the second
array level - you don't see the same spike in the second example.

Regards
Peter

On 16 March 2010 15:46, Robert Cummings rob...@interjinn.com wrote:


 Richard Quadling wrote:

 On 15 March 2010 23:45, Daevid Vincent dae...@daevid.com wrote:

 Anyone have a function that will return an integer of the number of
 dimensions an array has?

 /**
  * Get the maximum depth of an array
  *
  * @param array $Data A reference to the data array
  * @return int The maximum number of levels in the array.
  */
 function arrayGetDepth(array $Data) {
        static $CurrentDepth = 1;
        static $MaxDepth = 1;

        array_walk($Data, function($Value, $Key) use($CurrentDepth,
 $MaxDepth) {
                if (is_array($Value)) {
                        $MaxDepth = max($MaxDepth, ++$CurrentDepth);
                        arrayGetDepth($Value);
                        --$CurrentDepth;
                }
        });

        return $MaxDepth;
 }

 Extending Jim and Roberts comments to this. No globals. By using a
 reference to the array, large arrays are not copied (memory footprint
 is smaller).

 Using a reference actually increases overhead. References in PHP were mostly
 useful in PHP4 when assigning objects would cause the object to be copied.
 But even then, for arrays, a Copy on Write (COW) strategy was used (and is
 still used) such that you don't copy any values. Try it for yourself:

 ?php

 $copies = array();
 $string = str_repeat( '*', 100 );

 echo memory_get_usage().\n;
 for( $i = 0; $i  1000; $i++ )
 {
    $copies[] = $string;
 }
 echo memory_get_usage().\n;

 ?

 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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Need routine to tell me number of dimensions in array.

2010-03-16 Thread Peter Lind
Hmm, will probably have to look inside PHP for this ... the foreach
loop will copy each element as it loops over it (without actually
copying, obviously), however there's no change happening to the
element at any point and so there's nothing to suggest to the
copy-on-write to create a new instance of the sub-array.

It should look like this:
$a = array(0, 1, 2, array(0, 1, 2, 3), 4, 5, 6,  n);
$b = $a[3];
doStuffs($b);

Whether or not you loop over $a and thus move the internal pointer,
you don't change (well, shouldn't, anyway) $b as that's a subarray
which has it's own internal pointer, that isn't touched.

Or maybe I've gotten this completely backwards ...

Regards
Peter

On 16 March 2010 17:12, Robert Cummings rob...@interjinn.com wrote:
 Peter Lind wrote:

 This is one example where references actually decrease memory usage.
 The main reason is the recursive nature of the function. Try

 BTW, it's not the recursive nature of the function causing the problem. It's
 the movement of the internal pointer within the array. When it moves the COW
 realizes the copy's pointer has moved and splits off the copy. You can
 verify this by echoing the memory usage when you first enter carray(). The
 spike occurs inside the foreach loop.

 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





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] ldap_bind() connectivity

2010-03-15 Thread Peter Lind
You might want to check what the function outputs with:

var_dump($ldapbind);

after the call to ldap_bing(). That way you'll know what actually got
returned from the function.

On 15 March 2010 09:54, Ashley M. Kirchner ash...@pcraft.com wrote:
 Thanks to Jochem Mass for helping earlier to the string splitting.  Works
 great (so far).  Now on to my next problem, which has to do with
 ldap_bind().



 I have the following code:



      $ldapconn = @ldap_connect($adServer);

      $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass);



      if ($ldapbind) {

        /** Successful authentication **/

        $_SESSION['username'] = $username;

        $_SESSION['password'] = $password;

      } else {

        /** Authentication failure **/

        $form-setError($field, laquo; Invalid username or password
 raquo;);

      }

      ldap_unbind($ldapconn);



 The problem with this is that if the ldap_bind() fails in the second line,
 it instantly spits text out to the browser:



 Warning: ldap_bind() [function.ldap-bind
 http://www.smartroute.org/contest/include/function.ldap-bind ]: Unable to
 bind to server: Invalid credentials in /home/contest/include/session.php on
 line 351



 And because it does that, it never reaches the if routine right below it and
 everything just bombs.  If I call it with @ldap_bind($ldapconn .) nothing
 happens.  The error message gets suppressed but it also doesn't do anything
 with the if routine afterwards.  It's almost like $ldapbind isn't getting
 set at all.



 What am I missing here?





-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



Re: [PHP] Change displayed file name to download

2010-03-14 Thread Peter Lind
You can set the name to display as you see fit, just change $filename
to your liking right before the header() call. If you just want to cut
the path, use basename($filename)

Regards
Peter

On 14 March 2010 21:29, Php Developer pdevelo...@rocketmail.com wrote:
 Hi,

 I'm using the following code:
 
 $fp      = fopen($filename, 'r+');
 $content = fread($fp,
 filesize($filename));
 fclose($fp);
 header(Content-type:
 application/msword);
 header(Content-Disposition: attachment;
 filename=$filename);
 echo $content;
 exit;
 ___

 Now when downloading a file the default name that appears for the user is
 the realname of the file i the server with the real path the only
 difference is that the slashes are modified by underscore.

 My
 question is: is there any way how to control the name that will be
 displayed for the customer? Or at least skip the path and display just
 the file's name?

 Thank you


      __
 Be smarter than spam. See how smart SpamGuard is at giving junk email the 
 boot with the All-new Yahoo! Mail.  Click on Options in Mail and switch to 
 New Mail today or register for free at http://mail.yahoo.ca



-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
Flickr: http://www.flickr.com/photos/fake51
BeWelcome: Fake51
Couchsurfing: Fake51
/hype

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



[PHP] Using ArrayObject

2010-03-09 Thread Peter van der Does
What is the advantage of using ArrayObject to build a Registry class?

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



[PHP] Registry class question.

2010-02-26 Thread Peter van der Does
Hi,

I've build a registry class to store settings I need to use in several
other classes.

Currently I've set it up with a static array in the registry class and
using two methods to access the settings and values
storeSetting($key,$value) {
  $this-_settings[$key] = $value;
}

getSetting($key) {
  return $this-_settings[$key];
}

The question is what the pros and cons are compared to setting a new
property with the value, like:

storeSetting($key,$value) {
  $this-$key = $value;
}

and then instead of calling getSetting, you just use
$this-Registry-property

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



Re: [PHP] Stored Proc - Date not inserting into the Record

2010-02-25 Thread Peter

Change the input argument type as a varchar instead of date

Ex:
CREATE definer=`do...@`` PROCEDURE `Insert_OHC_Sun`(theDate 
VARCHAR(50),theDateRaw INT)


surly it will work

- Peter


Don Wieland wrote:

I nave 2 stored procedures:

DROP PROCEDURE IF EXISTS `Insert_OHC_Sun`;
DELIMITER $$
CREATE definer=`do...@`` PROCEDURE `Insert_OHC_Sun`(theDate 
DATE,theDateRaw INT)

BEGIN
  INSERT INTO Office_Hours_Cuttoff 
(ohc_Date,ohc_Date_Raw,Office_Status)

  VALUES (theDate,theDateRaw,Closed);
END
$$

DROP PROCEDURE IF EXISTS `Insert_OHC_Day`;
DELIMITER $$
CREATE definer=`do...@`` PROCEDURE `Insert_OHC_Day`(theDate 
DATE,theDateRaw INT)

BEGIN
  INSERT INTO Office_Hours_Cuttoff (ohc_Date,ohc_Date_Raw)
  VALUES (theDate,theDateRaw);
END
$$

Then I have PHP Code to insert a YEAR of days in a table:

if($_POST['new_year'])  {
//New Year
if(in_array($_POST['pick_year'], $ExistingYears))  {
$Message = brThe year .$_POST['pick_year']. is already 
existing.brPlease use the DELETE YEAR feature first. Then ADD the 
year again.br;

} else {

//Add Year
$first_day = mktime(0,0,0,1, 1, $_POST['pick_year']);
$last_day = mktime(0,0,0,12, 31, $_POST['pick_year']);

$cDate = $first_day;
$num = 1;


while($cDate = $last_day) {
  
$nDate = Date('Y-m-d', $cDate);


$db-next_result();
if(date('D', $cDate) == Sun) {
$db-query(CALL Insert_OHC_Sun({$nDate},{$cDate}));
}else{
   $db-query(CALL Insert_OHC_Day({$nDate},{$cDate}));
}

$cDate+=86400;
$num++;

}
}
}



The records are inserting into the table BUT the field och_Dates is 
not getting the proper value. It gets -00-00.


Frustrating. My code looks right and I echoed the value on the page 
and it is formatted properly. The field in mySQL is formatted as a 
DATE type.


Little help please :-)


Don Wieland
D W   D a t a   C o n c e p t s
~
d...@dwdataconcepts.com
Direct Line - (949) 305-2771

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our 
Developer Support Plan at:

http://www.dwdataconcepts.com/DevSup.html

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 
9 or higher

http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html




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



Re: [PHP] Stored Proc - Date not inserting into the Record

2010-02-25 Thread Peter

FYI

Please Pass your input within  quotes
$db-query(CALL Insert_OHC_Sun(*'*{$nDate}*'*,{$cDate}));

surly it will work

- Peter


Don Wieland wrote:

I nave 2 stored procedures:

DROP PROCEDURE IF EXISTS `Insert_OHC_Sun`;
DELIMITER $$
CREATE definer=`do...@`` PROCEDURE `Insert_OHC_Sun`(theDate 
DATE,theDateRaw INT)

BEGIN
  INSERT INTO Office_Hours_Cuttoff 
(ohc_Date,ohc_Date_Raw,Office_Status)

  VALUES (theDate,theDateRaw,Closed);
END
$$

DROP PROCEDURE IF EXISTS `Insert_OHC_Day`;
DELIMITER $$
CREATE definer=`do...@`` PROCEDURE `Insert_OHC_Day`(theDate 
DATE,theDateRaw INT)

BEGIN
  INSERT INTO Office_Hours_Cuttoff (ohc_Date,ohc_Date_Raw)
  VALUES (theDate,theDateRaw);
END
$$

Then I have PHP Code to insert a YEAR of days in a table:

if($_POST['new_year'])  {
//New Year
if(in_array($_POST['pick_year'], $ExistingYears))  {
$Message = brThe year .$_POST['pick_year']. is already 
existing.brPlease use the DELETE YEAR feature first. Then ADD the 
year again.br;

} else {

//Add Year
$first_day = mktime(0,0,0,1, 1, $_POST['pick_year']);
$last_day = mktime(0,0,0,12, 31, $_POST['pick_year']);

$cDate = $first_day;
$num = 1;


while($cDate = $last_day) {
  
$nDate = Date('Y-m-d', $cDate);


$db-next_result();
if(date('D', $cDate) == Sun) {
$db-query(CALL Insert_OHC_Sun({$nDate},{$cDate}));
}else{
   $db-query(CALL Insert_OHC_Day({$nDate},{$cDate}));
}

$cDate+=86400;
$num++;

}
}
}



The records are inserting into the table BUT the field och_Dates is 
not getting the proper value. It gets -00-00.


Frustrating. My code looks right and I echoed the value on the page 
and it is formatted properly. The field in mySQL is formatted as a 
DATE type.


Little help please :-)


Don Wieland
D W   D a t a   C o n c e p t s
~
d...@dwdataconcepts.com
Direct Line - (949) 305-2771

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our 
Developer Support Plan at:

http://www.dwdataconcepts.com/DevSup.html

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 
9 or higher

http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html




[PHP] Re: logic operands problem

2009-12-07 Thread Peter Ford
Merlin Morgenstern wrote:
 Hello everybody,
 
 I am having trouble finding a logic for following problem:
 
 Should be true if:
 page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3
 
 The result should never contain 1 AND 2 in the same time.
 
 This obviously does not work:
 (page = 1 OR page = 3) OR (page = 2 OR page = 3)
 
 This also does not work:
 (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page
 != 1)
 
 Has somebody an idea how to solve this?
 
 Thank you in advance for any help!
 
 Merlin


Surely what you need is xor (exclusive-or)
I can't believe a programmer has never heard of that!

(page==1 XOR page==2) AND page==3

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Class not returning value

2009-11-25 Thread Peter Ford
Pieter du Toit wrote:
 Hi
 
 This is my first class and it does not work, i do a return 
 $this-responseArray; with the public function getResult() method, but get 
 nothing. Can someone please help me.
 
 Thsi is how i create the object
 $number = new Smsgate($cell_numbers, $message, 27823361602, 27);
 $result = $number-getResult();
 
 Here is the code:
 ?php
 
 /**
  *
  * @version 1.0
  * @copyright 2009
  */
 
 /**
  */
 class Smsgate {
 
 protected $number;
 protected $message;
 protected $sender_id;
 protected $tofind;
 private $result;
 /**
  * Constructor
  */
 function __construct($number = , $message = , $sender_id = , 
 $tofind = )
 {
 
 $this-message = $message;
 $this-number = $number;
 $this-sender_id = $sender_id;
 $this-tofind = $tofind;
 }
 
 protected function display ($result)
 {
 return $result;
 }
 
 public function getResult()
 {
 return $this-processRequest();
 
 }
 public function numberErrors()
 {
 return $this-errorResult;
 }
 
 /**
  * Smsgate::checknumbers()
  *
  * @return array of correct and incorrect formatted numbers
  */
 private function processRequest()
 {
 echo nou by numers;
 print_r($this-number);
 // check if the property is an array and add to new array for 
 sending
 if (is_array($this-number)) {
 // check for starting digits
 $this-result = ;
 // loop through numbers and check for errors
 foreach ($this-number as $this-val) {
 
 $this-position = strpos($this-val , $this-tofind);
 
 // number correct
 if ($this-position === 0) {
 echo is integer br/;
 if ($this-result != ) {
 $this-result .= ,;
 }
 // create comma seperated numbers to send as bulk in 
 sendSMS method
 $this-result .= $this-val; //infobip multiple 
 recipients must be seperated by comma
 // create an array to use with responseStringExplode in 
 sendSMS method
 $this-cellarray[] = $this-val;
 echo Result is  . $this-result . br;
 } else {
 // numbers not in correct format
 $this-errorResult[] = $this-val;
 }
 
 } //end foreach
$this-sendSMS();
 
 } else {
 $this-result = Not ok;
  return $this-result;
 }
 
 }
 
 private function sendSMS()
 {
 
 $this-smsUrl = 
 'http://www.infobip.com/Addon/SMSService/SendSMS.aspx?user=password=';
 $this-post_data = 'sender=' . $this-sender_id . 'SMSText=' . 
 urlencode($this-message) . 'IsFlash=0GSM=' . $this-result;
 $this-sendData = $this-sendWithCurl($this-smsUrl, 
 $this-post_data);
 $this-responseStringExplode = explode(\n, $this-sendData);
 
  $count=0;
 foreach ($this-responseStringExplode as $this-rvalue) {
   $this-responseArray[$this-rvalue] = ($this-cellarray[$count]);
   $count = ++$count;
 }
  return $this-responseArray;
 }
  private function sendWithCurl($url, $postData) {
   if (!is_resource($this-connection_handle)) {
// Try to create one
if (!$this-connection_handle = curl_init()) {
 trigger_error('Could not start new CURL instance');
 $this-error = true;
 return;
}
   }
   curl_setopt($this-connection_handle, CURLOPT_URL, $url);
   curl_setopt ($this-connection_handle, CURLOPT_POST, 1);
   $post_fields = $postData;
   curl_setopt ($this-connection_handle, CURLOPT_POSTFIELDS, $post_fields);
   curl_setopt($this-connection_handle, CURLOPT_RETURNTRANSFER, 1);
   $this-response_string = curl_exec($this-connection_handle);
   curl_close($this-connection_handle);
   return $this-response_string;
  }
 }
 
 ? 
 
 


Based on a first scan of your code, it looks like the only return in
processRequest() is inside the else block, so nothing is returned unless the
processing fails.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Does PHP block requests?

2009-11-20 Thread Peter Ford
I have a tricky problem.

I'm trying to make a progress feedback mechanism to keep users informed about a
slowish process on the server end of a web app. The backend is generating a PDF
file from a bunch of data which extends to many pages. I can keep tabs on the
progress of this generation by working out how many lines of data is present,
and how much of it has been processed. I use that information to set a session
variable with a unique name - so for each step I set

$_SESSION['some-unique-name']=Array('total'=$totalLines,'count'=$linesProcessedSoFar);

Now on the front end I'm doing an AJAX call to a script that just encodes this
session variable into a JSON string and sends it back.

The problem is that while the PDF is being generated, the AJAX calls to get the
progress data (on a 1-second interval) are being blocked and I don't get why.
The PDF generation is also triggered by an AJAX call to a script which generates
the PDF in a given file location, then returns a URL to retrieve it with.

So it appears that the problem is that I can't have two AJAX calls to different
PHP scripts at the same time? WTF?

Checking the requests with Wireshark confirms the the browser is certainly
sending the progress calls while the original PDF call is waiting, so it's not
the browser side that's the problem: and once the PDF call is finished the
outstanding progress calls are all serviced (returning 100% completion of course
- not much use!) Different browsers (Firefox, IE, Chrome at least) give the same
result.

For reference, the server is Apache 2.2.10 on a SuSE linux 11.1 box using
mod_php5 and mpm_prefork - is that part of the problem, and is there an 
alternative?
-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Lightweight web server for Windows?

2009-11-19 Thread Peter Ford
O. Lavell wrote:
 
 Also, it is not for daily use. I have two desktop computers and a server 
 for that. This is for when I have to go by train or something.
 
 Essentially it is just an extra plaything.
 

Does the battery still hold enough charge for a train journey - that always
seems to be the first thing that goes on old laptops.
They make really good low-power servers for stuff like DNS or even firewalling
(as long as you can plug in enough network cards), but only when on mains power 
:(

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] How to call DLL in Javascript

2009-11-17 Thread Peter

Hi All,

I want to call dll in javascript

I tried the following script, but i got the error message 'ActiveXObject 
is undefined'

(Note : i have the feedback.dll in the same path only)


HTML
HEAD
script type='text/javascript' language='javascript'
function comEventOccured()
{

   try{
   var myobject;
   myobject = new ActiveXObject(feedback.dll);
   }catch(e){
   alert(e.description);
   return false;
   }

}
/script/head
body
input  type=button value=Call the DLL  onClick=comEventOccured()
/body
/html



Regards
Peter.

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



[PHP] How to call a vc++ dll from a HTML form

2009-11-17 Thread Peter

Thanks to All.

I want to call a vc++ dll from a HTML form. The dll need to be triggered 
on a button click in the HTML form.


I want to access the dll from the client end(javascrript) without using 
the server.


Tell me whether its possible to call dll directly or through any interface ?

Please provide me your valuable inputs to solve this issue.

Regards
Peter

Nathan Rixham wrote:

Peter wrote:
  

Hi All,

I want to call dll in javascript

I tried the following script, but i got the error message 'ActiveXObject
is undefined'
(Note : i have the feedback.dll in the same path only)


HTML
HEAD
script type='text/javascript' language='javascript'
function comEventOccured()
{

   try{
   var myobject;
   myobject = new ActiveXObject(feedback.dll);
   }catch(e){
   alert(e.description);
   return false;
   }

}
/script/head
body
input  type=button value=Call the DLL  onClick=comEventOccured()
/body
/html



Regards
Peter.



usually .dll should be running client side not server side

jscript and javascript are two different beasts based on ecmascript;
you'll be wanting to get some JScript (microsofts own version) help for
this.. http://msdn.microsoft.com/en-us/library/7sw4ddf8%28VS.85%29.aspx
but as somebody else mentioned, you won't get it working on all browsers
AFAIK.. so running DLL on server side and calling wrapper functions via
ajax is more appropriate.

an asp.net forum or suchlike will probably yield a more useful response

regards

  


[PHP] Re: fread() memory problems

2009-11-16 Thread Peter Ford
Ashley Sheridan wrote:
Ashley Sheridan wrote:
 I was just wondering why fread() seems to use so much memory when
 reading in a file. My php.ini has a script memory limit of 32MB, yet PHP
 hits its memory limit on a 19MB mbox file that I'm reading in. How is it
 possible that this function can use 150% of a files' size in memory?!
 
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 

Is it possible that the file is 8-bit characters and your PHP implementation is
converting it to 16-bit characters?
I'm not sure what settings would be involved for that, but no-one else has
responded so I thought a vague idea might be better than nothing!

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Multilingual website, texts in external JavaScriptproblem

2009-11-10 Thread Peter Ford
leledumbo wrote:
 I don't see why you can't use inline script in XHTML 1.0 Strict
 
 Because I don't know about CDATA, thanks.

Glad to be of service!
As another regular contributor to this list often points out, there's always
something new to learn :)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Multilingual website, texts in external JavaScript problem

2009-11-09 Thread Peter Ford
leledumbo wrote:
 I need to create a multilingual website and my framework already gives me
 that facility. However, I also use JavaScript quite extensively and since
 XHTML 1.0 Strict doesn't allow inline script, I must use external .js file.
 The problem is in these scripts, there are strings that needs to be
 translated as well. How can I make PHP parse these scripts as well? Or are
 there alternative approaches?
 

I don't see why you can't use inline script in XHTML 1.0 Strict: just put the
script in CDATA sections, like

script type=text/javascript
/*![CDATA[*/

// Inline javascript here

/*]]*/
/script

That seems to validate fine in XHTML 1.0 Strict for me...


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Spam opinions please

2009-10-23 Thread Peter Ford
Ashley Sheridan wrote:
 
 
 Won't stop a bot worth it's salt either, hence the need for more complex
 and confusing captchas. The best way to stop spam, is to use linguistic
 testing on the content being offered, which protects against bot and
 human spammer alike.
 
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 
 

Unfortunately, it might also confound someone who doesn't speak the language.
Admittedly, they would probably already be struggling with the rest of the 
site...

I guess locale-dependent captchas are a possibility.


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Fun with XSLT

2009-10-22 Thread Peter Ford
Matthew Croud wrote:
 Hi Guys,
 
 Well i;ve been slaving on with my PHP XML endeavors and i'm loving it,
 just finishing the meaty parts of my XSLT for dummies book too.
 
 I have a question which asks is it possible?.
 
 Using XSLT I can collect specific parts of my XML using something sexy
 like xsl:template match=umbungo.  Lets say however, that I need to
 use XSLT, but I would want the user to select which element they
 request. In other words, they are given a form with options and that
 form can manipulate the .XSL file.
 
 Now I know it could be done in a lengthly manner by just opening the XSL
 file and manipulating it like fopen or something like that, but is there
 a way to somehow embed the contents of the xml into the php code (like
 using  EOF for html), and being able to substitute the template match
 string for a variable ?
 
 Any ideas ?
 
 Thanks Gamesmaster,
 Matt
 
A bit off-topic (since XSLT is not PHP...) but here goes.

First I need to clarify what you are doing -
xsl:template match=umbongo ... /xsl:template
defines the template portion, and that is pretty immutable.

At some point you must have in your XSLT something like
xsl:apply-templates select=umbongo/
This is the bit you can play with:

so:


xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform;
xsl:output method=xml encoding=UTF-8 / !-- or whatever --

!-- Pass in a parameter to the XSL to define which thing we want to match --
xsl:parameter name='matchMe'/

!-- Define templates for all the things we might want to match --
xsl:template match='umbongo'xsl:apply-templates//xsl:template
xsl:template match='fivealive'xsl:apply-templates//xsl:template
!-- etc. --

!-- now the clever bit --
xsl:template match='/'
xsl:apply-templates select='//*[name()=$matchMe]'/
/xsl:template

/xsl:stylesheet

Essentially you need to apply the template of any element, but only those whose
name matches your request.
Note that
xsl:apply-templates select='$matchMe]'/
doesn't work... :(

So now if your PHP does something like

$xslDom = new DOMDocument();
$xslDom-load('matchMe.xsl');
$xslt = new XSLTProcessor();
$xslt-importStylesheet($xslDom);
$xslt-setParameter('','matchMe','umbongo');
$xmlDom = new DOMDocument();
$xmlDom-load('some_document_that_has_an_umbongo_tag.xml');
echo $xslt-transformToXML($xmlDom);

you should get the results of the 'umbongo' template (only)


'f course, this is not tested, but I have used this idea in working code




-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Fun with XSLT

2009-10-22 Thread Peter Ford
Matthew Croud wrote:
 Hi Guys,
 
 Well i;ve been slaving on with my PHP XML endeavors and i'm loving it,
 just finishing the meaty parts of my XSLT for dummies book too.
 
 I have a question which asks is it possible?.
 
 Using XSLT I can collect specific parts of my XML using something sexy
 like xsl:template match=umbungo.  Lets say however, that I need to
 use XSLT, but I would want the user to select which element they
 request. In other words, they are given a form with options and that
 form can manipulate the .XSL file.
 
 Now I know it could be done in a lengthly manner by just opening the XSL
 file and manipulating it like fopen or something like that, but is there
 a way to somehow embed the contents of the xml into the php code (like
 using  EOF for html), and being able to substitute the template match
 string for a variable ?
 
 Any ideas ?
 
 Thanks Gamesmaster,
 Matt
 

Despite my other post, of course you can generate the XSL on the fly:

?php
$choice='umbongo';

$xslScript EoXSL
xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform;
xsl:output method=xml encoding=UTF-8 /

xsl:template match='/'
xsl:apply-templates/
/xsl:template

xsl:template match='{$choice}'xsl:apply-templates//xsl:template
/xsl:stylesheet
EoXSL

$xslt = new DOMDocument();
$xslt-loadXML($xslScript);

// ... etc...
?




-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Spam opinions please

2009-10-20 Thread Peter van der Does
On Tue, 20 Oct 2009 14:31:53 -0400
Gary gwp...@ptd.net wrote:

 I have several sites that are getting hit with form spam.  I have the
 script set up to capture the IP address so I know from where they
 come.  I found a short script that is supposed to stop these IP
 addresses from accessing the form page, it redirects the spammer to
 another page (I was going to redirect to a page that has lots of
 pop-ups, scantily clad men and offers of joy beyond imagination), but
 someone suggested I redirect to the Federal Trade Commission or
 perhpas the FBI.
 
 Any thoughts on the script and its effectivness?
 
 ?php
 $deny = array(111.111.111, 222.222.222, 333.333.333);
 if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header(location: http://www.google.com/;);
exit();
 } ?Gary 
 
 

There are several options to stop spammers, although none of them will
completely eliminate all spam. For a forum I prefer the .htaccess
method.

There is a website dedicated to keeping track of forum spammers,
http://stopforumspam.com and  depending on your forum you could add an
anti-spam mod that will query their database. On the site they have
mods for phpbb, vBulletin and SMF.

I wrote a Python script that uses a Python Library that's also posted
on their site. The Python program basically use an Apache log file for
the IP's checks them at Stop Forum Spam and adds spam IP in
the .htaccess file. I have it set up in cron to run daily.
For a little bit more detailed description and the program itself:
http://blog.avirtualhome.com/2009/10/08/stop-spammers-in-your-htaccess/


-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

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



[PHP] Re: avoid Denial of Service

2009-10-09 Thread Peter Ford
Gerardo Benitez wrote:
 Hi everybody!
 
 
 I want to get some tips about how avoid a attack of Denial of service.  May
 be somebody can about your experience with Php o some configuration of
 apache, o other software that help in these case.
 
 
 Thanks in advance.
 
 

Unplug the network cable :)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: php/mysql Query Question.

2009-09-16 Thread Peter Ford
ad...@buskirkgraphics.com wrote:
 Before most of you go on a rampage of how to please read below...
 
 As most of you already know when using MySQL from the shell you can write 
 your queries in html format in an out file.
 
 Example:   shellmysql -uyourmom -plovesme --html
 This now will return all results in an html format from all queries.
 
 Now I could “tee” this to a file and save the results returned if I so choose 
 to save the result of the display .
 
 Let’s say I want to be lazy and write a php MySQL query to do the same so 
 that any result I queried for would return the html results in a table 
 without actually writing the table tags in the results.
 
 Is there a mysql_connect or select_db or mysql_query tag option to do that 
 since mysql can display it from the shell?

I think you'll find that the HTML output is a function of the mysql command line
program (I tend to use PostgreSQL, where 'psql' is a similar program) so you can
only access that functionality by calling the command line.

I suspect that, since PHP is a HTML processing language (originally), the
creators of the mysql_ functions figured that the user could sort out making
HTML from the data returned...

It's should be a simple operation to write a wrapper function to put HTML around
the results. There might even be a PEAR extension or PHPClasses class to do it
(I haven't looked yet)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Return XML attribute in DOM

2009-09-08 Thread Peter Ford
Matthew Croud wrote:
 Doesn't the DOM have the getAttribute() method?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk
 
 It's not in my reference, though I see it in the PHP manual now.
 This is what I have:
 
 _
 
 $dom = new DomDocument();
 $dom - load(items.xml);
 
 $topics = $dom - getElementsByTagName(item);
 
 echo(ul);
 foreach ($topics as $node )
 {
 echo(li. $node - hasAttributes() ./li);   
 }
 echo(/ul);
 
 __
 
 I'm replacing hasAttributes() with getAttribute() but its throwing me an
 error, I'm probably using it incorrectly.
 I think I'm drowning in the deep end =/
 Could you advise Gamesmaster ?


It's a method on DomElement:
http://uk3.php.net/manual/en/function.domelement-get-attribute.php

and you need to tell it which attribute to get... :)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] IRC and English

2009-09-02 Thread Peter Ford
tedd wrote:
 At 2:02 PM -0700 9/1/09, Jessi Berkelhammer wrote:
 As a monolingual North American, I am also very uncomfortable with
 this thread.

 A rant about abbreviations/IRC jargon is an appropriate discussion for
 list, but criticizing how non-native English speakers write English is
 not. This thread began with a mention of the attitude that
 non-native English speakers have, as if non-native English speakers
 are a unified group that are are more likely to have a bad attitude
 than native English speakers. Of course such a generalization could
 make people uncomfortable.

 -jessi

 tedd wrote:
  At 11:16 AM -0300 9/1/09, Martin Scotta wrote:
  As a non-english speaker I feel very uncomfortable with this thread.

   You shouldn't feel uncomfortable because no one is talking about you.
  
 
 As a fellow monolingual North American, I feel very uncomfortable about
 your statement as well. Does any other monolingual North American feel
 the same way as I do? Please expound on your feelings about this most
 disheartening and distasteful topic. (Boy has this thread degenerated
 into some politically correct bullsh#t, huh?)
 
 Look if you are not the one using u as a substitute for you, then I
 don't see any support for the discomfort you may feel about this thread.
 But you are free to feel as it is your nature (shudder).
 
 If non-English users (or anyone else for that matter) want to use u
 for you that's fine -- but I'll refrain from helping them as well. I
 am sure that if I were writing in their language and shortened it to
 uncomprehending gibberish, I would receive the same treatment from them.
 Why is this so hard to understand -- am I using words that are two lengthy?
 
 Cheers,
 
 tedd
 


Words that are two lengthy: of, an, to, it (etc.)
Words that are too lengthy: antidisestablishmentarianism,
internationalisation and that other one that begins with flocci... something

Sorry tedd :)

+1 on hating l33tsp34k and txtspk though (not tho). The American standardisation
of English spelling did quite enough damage to the beautiful language of
Shakespeare (who couldn't even spell his own name consistently), without any
more neologisms creeping in.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] CodeWorks 09

2009-09-02 Thread Peter Ford
Jim Lucas wrote:
 Elizabeth Naramore wrote:
 Hey all,
 Just wanted to make sure you knew about php|architect's upcoming
 CodeWorks
 conference, coming to 7 cities in 14 days:

 - San Francisco, CA:  Sept 22-23
 - Los Angeles, CA:  Sept 24-25
 - Dallas, TX:  Sept 26-27
 - Atlanta, GA:  Sept 28-29
 - Miami, FL: Sept 30 - Oct 1
 - Washington, DC: Oct 2-3
 - New York, NY: Oct 4-5

 Each two-day event includes a day of *in-depth PHP tutorials* and a
 day of *PHP
 conference talks* arranged across three different tracks, all
 presented by
 the *best experts* in the business.

 Each event is limited to 300 attendees and prices increase the closer
 we get
 to each event. Get your tickets today before we run out or the price goes
 up!

 For more information and to register, you can go to http://cw.mtacon.com.
 Hope to see you there!

 -Elizabeth

 
 Is their anything like this in the Pacific NORTH WEST??
 
 Seattle or Portland Oregon area would be great!
 

Or even in the rest of the world - PHP is bigger than just the USA :)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Re: unset() something that doesn't exist

2009-08-27 Thread Peter Ford
Stuart wrote: (among other things)
 If you ask me you are essentially describing engineers (or doers) as
 idiots and salespeople as morons. I won't debate the labels but
 unfortunately it's a fact of life that most management types in this
 world are ex-sales because they're the ones who know how to use their
 skills to further their career which them in a position to favour
 sales over engineering when it comes to salary and rewards.
 

I think you'll find it's because the engineers like engineering and not
managing, so they (if they can get away with it) avoid or decline the
opportunities for promotion to management.

ISTR the Royal Air Force has a Specialist Aircrew track where the really good
pilots, who wanted to fly planes rather than desks, could be promoted to
management ranks but avoid the management duties.
I had the pleasure of meeting one of these chaps when I was at university - he
had more flying hours than I had lived and flown just about everything with
wings. A superb instructor, but far too much of a livewire to be a manager...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] SESSIONS lost sometimes

2009-08-20 Thread Peter Ford
Leon du Plessis wrote:
  It's not an issue, it's a feature.
 
 Thanks Arno...but it is a pain also.
 If I work with user A in Tab1 (window1), I want to work with user B
 separately in Tab2. When user in Tab2 logs off, I still want user A to work,
 and not suddenly have to re-login. Same with bank. If I work with my company
 account, then my personal account must not become an issue because I am on
 the same machine and site. 
 
 I have no issue with using FF and IE to do testing as that takes care of
 browser compatibility testing at the same time :-), but I think when you
 start a new session with new values, it should be kept under that window/tab
 alone. Cookies can take care of more details, but my opinion is data should
 never be affected across windows/tabs unless the same user is logged in on
 botheven then I would expect PHP to keep data per session. Maybe it goes
 beyond being an IE or FF issue..the questiojn is...will PHP allow variables
 from session A become corrupted when session B is in progress when they
 should actually be handled seperately?
 
 In the end I think it is something I do wrong in PHP with the SESSION
 variables and how I clear themif so...I don't think PHP should allow
 clearing SESSION variables from other sessions.
  
 -Original Message-
 From: Arno Kuhl [mailto:ak...@telkomsa.net] 
 Sent: 20 August 2009 10:03 AM
 To: 'Leon du Plessis'; php-general@lists.php.net
 Subject: RE: [PHP] SESSIONS lost sometimes
 
 -Original Message-
 From: Leon du Plessis [mailto:l...@dsgnit.com] 
 Sent: 20 August 2009 09:44 AM
 To: php-general@lists.php.net
 Subject: RE: [PHP] SESSIONS lost sometimes
 
 Since we are on the subject: I have the following similar problem:
 
 When testing page on internet explorer, I find that one tab's variables can
 affect another tab's variables. Thus when having the same web-site open and
 using SESSION variables but for different users, Internet explorer can
 become disorientated. This also sometimes happen when I have two
 separate browsing windows open with Internet Explorer for the same site.
 
 I have yet to determine if this is an internet explorer, or PHP or
 combination of the two that is causing this condition. 
 
 To my understanding _SESSION variables should be maintained per session, tab
 or window. If this has been addressed already, my apologies, but thought it
 worthwhile to mention.  
 
 If someone perhaps have a solution or can confirm this as a known issue and
 maybe is the same or related to Angelo's problem?
 
 
 
 If different browser windows/tabs on the same client-side computer didn't
 share session info then you'd get the effect of being able to log onto a
 site with one browser window, but find in a second browser window that you
 were not yet logged on. Experience will tell you that you're logged on in
 both browser windows (try it with your online bank). It's not an issue, it's
 a feature. If you want to be able to use different browser windows as though
 they were different users then use different browsers e.g. IE and FF on the
 same client-side computer will look like two separate end users to the
 server, and they don't share session info or cookies.
 
 Cheers
 Arno
 
 

The key thing is that both tabs (or windows) from the same browser are in the
*same* session - they send the *same* PHPID cookie. PHP is essentially stateless
- it doesn't care where the request comes from, and ties a session to the PHPID
cookie if it gets one. As far as PHP knows, requests from different tabs with
the same PHPID cookie are requests from the same place in the same session.

To get a different session you need a different instance of the browser - that's
the way browsers have been coded to work. It's not too hard with Firefox, since
you can set up multiple profiles to have independent Firefox windows on the same
screen.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Form Spam

2009-08-20 Thread Peter van der Does
On Thu, 20 Aug 2009 09:11:47 -0400
Gary gwp...@ptd.net wrote:

 I have a client with a form on his site and he is getting spammed.
 It appears not to be from bots but human generated.  While they are
 coming from India, they do not all have the same IP address, but they
 all have gmail addresses, New York  addresses are used in the input
 field and they all offer SEO services.  It is not overwhleming, but
 about 5 a month.
 
 What is the best way to stop this.
 
 Thanks
 
 Gary 
 

One of the things you could check is if they do direct posting.
What I mean by that if that sometimes a POST URL only is send. They
figured out the fields you have in your form and directly send a POST
with the appropriate fields.
You could check this in the webserver logs. Just look for the IP and
see if it only has a POST URL.

If this is the case you could implement a nonce on your form and check
it during the processing of the post.

A second idea is to check the IP of the visitor during the POST
process, with something like stopforumspam or project honey pot.

If you want more info let me know.


-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com


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



[PHP] is there any way to get realpath cache hit ratio of php?

2009-08-11 Thread Peter Wang
hi,

Is there any way to get realpath cache hit ratio of php?


realpath_cache_size integer

Determines the size of the realpath cache to be used by PHP. This
value should be increased on systems where PHP opens many files, to
reflect the quantity of the file operations performed.

realpath_cache_ttl integer

Duration of time (in seconds) for which to cache realpath information
for a given file or directory. For systems with rarely changing files,
consider increasing the value.

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



[PHP] Is there any considerations for not putting php scripts in tmpfs?

2009-08-10 Thread Peter Wang
Hi php-general,
sorry if it is a wrong lists for this question.

I have read many articles/messages about using tmpfs store temp files,

for example, php session data, smarty compied templates and so on.

An obvious reason for that is: it doesn't matter about data loss caused by
machine restart/poweroff.

since it is not that difficult to restore files on a tmpfs from a disk-based
dir when machine boot up.

so may i put all my php scripts on a tmpfs to speed it up?  would that cause
other issues?

thanks for your advices.


Re: [PHP] Is there any considerations for not putting php scripts in tmpfs?

2009-08-10 Thread Peter Wang
hi,thanks for your reply.



On Mon, Aug 10, 2009 at 9:54 PM, Richard Quadling
rquadl...@googlemail.comwrote:

 2009/8/10 Peter Wang ptr.w...@gmail.com:
  Hi php-general,
  sorry if it is a wrong lists for this question.
 
  I have read many articles/messages about using tmpfs store temp files,
 
  for example, php session data, smarty compied templates and so on.
 
  An obvious reason for that is: it doesn't matter about data loss caused
 by
  machine restart/poweroff.
 
  since it is not that difficult to restore files on a tmpfs from a
 disk-based
  dir when machine boot up.
 
  so may i put all my php scripts on a tmpfs to speed it up?  would that
 cause
  other issues?
 
  thanks for your advices.
 

 Considering that in the main PHP scripts are readonly, I would have
 thought the normal file and disk caching of the OS would suffice.


normal file/disk caching of the OS works for small amount of files,
but when your apps has huge amounts of files, that doesn't work any more.
even with APC, it still cause many stat() system calls.






 --
 -
 Richard Quadling
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 Standing on the shoulders of some very clever giants!
 ZOPA : http://uk.zopa.com/member/RQuadling



[PHP] Re: Clean break.

2009-08-03 Thread Peter Ford
Paul Halliday wrote:
 Whats the cleanest (I have a really ugly) way to break this:
 
 [21/Jul/2009:00:00:47 -0300]
 
 into:
 
 date=21/jul/2009
 time=00:00:47
 
 Caveats:
 
 1) if the day is  10 the beginning of the string will look like 
 [space1/...
 2) the -0300 will differ depending on DST or TZ. I don't need it
 though, it just happens to be there.
 
 This is what I have (it works unless day  10):
 
 $theParts = split([\], $theCLF);
 
 // IP and date/time
 $tmpParts = explode( , $theParts[0]);
 $theIP = $tmpParts[0];
 $x = explode(:, $tmpParts[3]);
 $theDate = str_replace([,, $x[0]);
 $theTime = $x[1]:$x[2]:$x[3];
 
 the full text for this part looks like:
 
 10.0.0.1 - - [21/Jul/2009:00:00:47 -0300] ... more stuff here
 
 Anyway, any help would be appreciated.
 
 thanks.


As far as I can tell from a brief test, date_create will happily parse your
format, so something like

$tmp = date_create($theParts[0]);
$theDate = $tmp-format(d/m/Y);
$theTime = $tmp-format(h:i:s);

should do it


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: file upload question

2009-08-03 Thread Peter Ford
seb wrote:
 Hey all,
 
 i am using move_upload function to upload files to the server, but i
 want to add a feature that will allow files to be archived that have
 been uploaded already.
 
 so, the problem is:
 
 i upload a file that i want to upgrade and move the old file to an
 archive directory but I want to verify the NEW file is upload BEFORE
 moving the old file (the file being uploaded might not have the same
 filename as the old file currently on the server)..
 
 i want to move the old file only when the new file was successfully
 uploaded. something like:
 
 if(move_uploaded_file())
 {
rename(...);
 }
 
 only one problem.. then if both files have the same name it will be
 overwritten before it moves the old one i want to save. if i move the
 old one first, there still the possibility of the new upload failing so
 i am back to square one..
 
 i guess i can move_upload to a different directory, verify it's been
 uploaded, move the old to the archive file, then move the new file back
 to where it should be (where the archive file was)..
 
 is that my only option? any suggestions?

I'd suggest you *copy* the old file (if it exists) to archive anyway, and then
*move* it back if the new version doesn't verify. That seems pretty safe to 
me...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] fileinfo returning wrong mime type for Excel files

2009-07-30 Thread Peter Ford
Christoph Boget wrote:
 /usr/share/file/magic
 /usr/share/file/magic has lots of rules to know its type and its just
 matching it.
 
 I know it has a lot of rules.  Grepping it for excel shows that there
 are rules in it for those types of files as well.
 
 Maybe your file is quite strange . have you tried with other xls files?
 
 Yes, I have; the result is the same for all.
 
 what does  file /path/to/my/excel.xls  say
 
 $ file excel.xls
 excel.xls: Microsoft Office Document
 
 Interestingly...
 
 $ file word.doc
 word.doc: Microsoft Office Document
 
 So apparently, to the file command, there is no distinction.  That
 seems both odd and wrong to me.  But not nearly as wrong as fileinfo
 reporting application/msword as the mime type of an excel document.
 
 thnx,
 Christoph


Have you tried using 'file -i' from the command line: after all you are looking
for a MIME type with your fileinfo...

Having said that, with file -i on my system, Word documents are
'application/msword' and Excel files are 'application/octet-stream'

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Broken IF behavior? (Changing the branch changes the evaluation)

2009-07-29 Thread Peter Ford
Matt Neimeyer wrote:
 It's exactly what I would expect... The content of the row... But in
 any case, what does changing the content of the { } branch have to do
 with how the IF() itself is evaluated?
 
 array(4) {
   [0]=
   string(8) CustName
   [config]=
   string(8) CustName
   [1]=
   string(11) Sample Cust
   [value]=
   string(11) Sample Cust
 }
 
 

The if() *is* being evaluated *the same* whatever the content of that branch,
but when there's no content, you see no result...

It always looks odd to me to have empty if branches - why do you not just write

if ($Ret) { return $Ret; }

Anyway, the !$Ret branch is being executed because the fetch operation will
return NULL (or FALSE or something equivalent) when there are no results.



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: newbie question - php parsing

2009-07-23 Thread Peter Ford
João Cândido de Souza Neto wrote:
 You made a mistake in your code:
 
 ?php the_title(); ?
 
 must be:
 
 ?php echo the_title(); ?
 

Not necessarily: what if you have

function the_title()
{
echo Title;
}

for example...


In response to Sebastiano:

There would be not much point in using something like PHP if it ignored the if
statements in the code!
What effectively happens in a PHP source file is that all the bits outside of
the ?php ? tags are treated like an echo statement (except that it handles
quotes and stuff nicely)

Your original code:

?php if (the_title('','',FALSE) != 'Home') { ?
h2 class=entry-header?php the_title(); ?/h2
?php } ?

can be read like:

?php
if (the_title('','',FALSE) != 'Home') {
echo 'h2 class=entry-header';
the_title();
echo '/h2';
}
?

You might even find a small (but probably really, really, really small)
performance improvement if you wrote it that way, especially if it was in some
kind of loop.
Note that I prefer to keep HTML separate from PHP as much as possible because it
helps me to read it and helps my editor check my syntax and HTML structure 
better...


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Undefined Index ...confusion

2009-07-23 Thread Peter Ford
Miller, Terion wrote:
 I keep getting this error while trying to use the field 'ID' to pass in a 
 url.. And it's odd because the query is pulling everything BUT the ID which 
 is the first field...
 
 code:
 a href=view.php?ID=?php echo 
 $_SESSION['fullRestaurantList']['ID']??php echo 
 htmlspecialchars(stripslashes($_SESSION['fullRestaurantList'][$i]['name'])); 
 ?

What's the query?

I find (I use PostgreSQL rather than the mySQL that many on this list use) that
unless you explicitly ask for a field called ID (using  SELECT ID ... ) you
get a returned field in lower case
So
$resource = pg_query(SELECT ID, Foo FROM MyTable WHERE Foo='Bar');
$data = pg_fetch_all($resource)

gives me an array $data of rows like
$data[0]['id'] = '1'
$data[0]['foo'] = 'Bar'

To make sure $data[] has fields named ID and Foo I would have to do

$resource = pg_query(SELECT ID AS \ID\, Foo AS \Foo\ FROM MyTable WHERE
Foo='Bar');


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] [GD] Image errors

2009-07-15 Thread Peter Ford
Ash, Martin,

Seems you are both wandering around the obvious problem...

I suspect that $tipo (in the next line) is *supposed* to be $type - sounds like
a partial Italian translation to me...

So given that $type=imagecreatefrompng (for example, if the mime check returns
'png' - not very reliable, I suspect),

then

$immagine = $type($this-updir.$id.'.png')

should create a GD resource from the file, but the image appears to be empty.

My take on this is:

OP says he gets the same result from
$immagine = imagecreatefromjpeg(this-updir.$id.'.png')

- well I might expect to get an error message if I loaded a PNG expecting it to
be a JPEG, but I certainly wouldn't expect an image.

On some basic tests, I find that mime_content_type() is not defined on my
system, so ignoring that and trying to load a PNG file using imagecreatefromjpeg
results in pretty much the same result as the OP...

Conclusions:

First: if you use Italian for your variable names, don't change half of their
instances to English...

Second: Make sure you actually know the mime type of a file before you try to
load it into GD...

My version of this would test against known image types to try the GD function:

foreach (Array('png','jpeg','gif') as $typeName)
{
  $type = 'imagecreatefrom'.$typeName;
  $immagine = $type(this-updir.$id.'.png'le);
  if (is_resource($immagine))
  {
header('Content-type: image/jpeg');
imagejpeg($immagine,null,100);
imagedestroy($immagine);
break;
  }
}
header('HTTP/1.0 500 File is not an allowed image type');





-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] [GD] Image errors

2009-07-15 Thread Peter Ford
Martin Scotta wrote:
 Why are you ussing GD?
 All you need is output the image to the browser?
 
 try this... I didn't test/run this code, but it may work...
 
 public function showPicture( $id ) {
   header('Content-type:' . mime_content_type( $this-updir . $id .
 '.png' ) );
   readfile( $this-updir . $id . '.png' );
   }
 
 hey, look, just 2 lines!
 
But it doesn't convert the image from whatever came in to a JPEG output, which
is what the OP's code appears to be trying to do (and possibly ought to work...)



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Scope woe

2009-06-30 Thread Peter Ford
Luke wrote:
 Hello again guys,
 
 I was wondering the best way to tackle the following problem:
 
 I've got a class, containing a property which is another object. So from
 outside I should be able to do
 $firstobject-propertycontainingobject-methodinsidethatobject();
 
 The $firstobject variable is in the global namespace (having been made with
 $firstobject = new FirstObject;), and I'm having a problem that I'm sure
 many people have when accessing it inside another class, so:
 
 class otherObject
 {
 static function messwithotherthings ()
 {
 $firstobject-propertycontainingobject-methodinsidethatobject();
 }
 }
 
 But $firstobject is blank, which makes sense because in there it is pointing
 to the local variable within the method.
 
 To solve this, I could add 'global $firstobject' inside every method, but
 this is very redundant and boring. I've tried a couple of things like
 adding:
 
 private $firstobject = $GLOBALS['firstobject'];
 
 But apparently that's bad syntax. I was just wondering the best way to get
 around this?
 
 Thanks a lot for your help,
 


Set the value of $firstobject in the constructor of otherObject (that's what
constructors are for!):

eg.

class otherObject
{
private $firstobject;

function __construct()
{
$this-firstobject = $GLOBALS['firstobject'];
}

static function messwithotherthings ()
{
$this-firstobject-propertycontainingobject-methodinsidethatobject();
}
}


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Re: Scope woe

2009-06-30 Thread Peter Ford
Luke wrote:

 Thanks for the replies :)
 
 Surely if I pass it as a parameter to the __construct then I would have to
 make an instance of the otherObject, notice that messwithotherthings is
 static?
 
 Also, if I'm not using OOP properly, Eddie, how would I use it properly to
 prevent this situation?
 
 Thanks,
 

Hmmm, I didn't notice the method was static - that means my idea really won't
work...

I did have a bad feeling about this, and Eddie confirmed my unease with the
point about OOP.

Really, you should need your $firstobject to be a singleton:
eg.

class FirstObject
{
private static $theInstance = NULL;

public $propertyContainingObject;

protected function __construct()
{
// whatever
}

public static function getInstance()
{
if (!self::$theInstance)
{
self::$theInstance = new FirstObject();
}
return self::$theInstance;
}

// ... other methods ...
}


So then:

class OtherObject
{
static function messWithOtherThings()
{
$firstObject = FirstObject::getInstance();
$firstObject-propertyContainingObject-methodInsideThatObject();
}
}



I think that works, and is reasonable to the OOP purists...


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] I've some doubts if I should go with 5.2 or go alreadywith 5.3 (for a course)

2009-06-23 Thread Peter Ford
Robert Cummings wrote:
 Per Jessen wrote:
 Manuel Aude wrote:

 I'm giving a PHP course next semester (3 hours all saturdays for 22
 weeks) and I just realized that PHP 5.3 is coming very soon (2 days
 now!). So, my plans of teaching PHP 5.2 are starting to change, and I
 think it's a good idea to teach them 5.3 already.

 Does it _really_ matter which one?  I can't imagine there are that many
 revolutionary changes in a dot-release.
 
 Given the naming of PHP versions of PHP-x.y.z, I would agree that not
 much changes between versions at the .z level. But at the .y level there
 are usually significant changes.
 
 Coming to a PHP 5.3 near you are the following notable features:
 
 - namespaces
 - closures
 - late static binding
 - garbage collector to handle cyclic references
 - PHAR
 - goto
 
 Cheers,
 Rob.

I read that last bit as
PHAR
togo

Need coffee...



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Echo result in a loop on each instance

2009-06-23 Thread Peter Ford
Anton Heuschen wrote:
 I have a question regarding echo of a var/string in a loop on each instance
 
 A shortened example:
 
 Lets say I have an array of values (rather big), and then I loop
 through this array:
 
 for or foreach :
 {
$value = $arrValAll[$i];
 
echo test.$i.-- .$value;
 }
 
 
 When the script runs it will only start to echo values after certain
 period ... it does not echo immediately ... how can I force it start
 echo as soon as the first echo instance is done ? I thought ob_start
 does this but I have tried it and not getting what I want.
 
 Is there some other way/correct to do this?


call flush() after each echo to flush the buffer to the client.
That should work...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: accessing level above $_SERVER['DOCUMENT_ROOT']

2009-06-19 Thread Peter Ford
LAMP wrote:
 hi,
 
 I have this structure:
 /home/lamp/mydomain/html
 /home/lamp/mydomain/logs
 /home/lamp/mydomain/config
 etc.
 
 html directory is the only one accessible from outside.
 
 to access config file I can use this:
 required_once('/home/lamp/mydomain/config');
 
 but this is the structure on my local/development machine. once the site
 is done it will be moved to production server and the structure will be
 /srv/www/mydomain/html
 /srv/www/mydomain/logs
 /srv/www/mydomain/config
 etc.
 
 to automate the document_root I define on the begining of the page
 
 define('HTML_PATH', $_SERVER{DOCUMENT_ROOT']);
 define('CONFIG_PATH', $_SERVER{DOCUMENT_ROOT'].'/../config');
 define('LOGS_PATH', $_SERVER{DOCUMENT_ROOT'].'/../logs');
 
 it works but I think it's not good solution. or at least - it's not nice
 solution :-)
 
 suggestions?
 
 afan
 
 

Outside of a define, you could have used dirname($_SERVER[DOCUMENT_ROOT]), but
in a define, that's not going to work.
I think you're stuck with your inelegance...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-18 Thread Peter Ford
PJ wrote:
 I'm including the relevant code:
 
 // select categories for book to be updated
 $sql = SELECT id, category FROM categories, book_categories
 WHERE book_categories.bookID = '$bid' 
 book_categories.categories_id = categories.id;
 if ( ( $results = mysql_query($sql, $db) ) ) {
   while ( $row = mysql_fetch_assoc($results) ) {
 $selected[] = $row['id'];
 }
   }
 else $selected = Array( 0 = '0');
 echo $selected;
 print_r($selected);
 
 $sql = SELECT * FROM categories;
 echo select name='categoriesIN[]' multiple size='8';
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 if (in_array($row['id'], $selected)) {
echo option value=, $row['id'],  selected='selected'
 , $row['category'], /optionbr /;
}
else echo option value=, $row['id'], ,
 $row['category'], /optionbr /;
 }
 }
 
 Problem #1)in the first query result. I can't figure out how to deal
 with it. The code works fine if there are categories assigned to the
 book. If not, an undefined variable error is spewed out for selected.
 

That's because the test you use for the success of the query:
( ( $results = mysql_query($sql, $db) ) !== false )
is true if and only if the query succeeds, whether or not you get any rows 
returned.
You then start looping over the fetched rows, and if there are none $selected
never gets anything assigned to it, and so never gets defined.

Since you don't rely on $selected being actually populated (in_array works fine
on an empty array...), you might be better off pre-setting $selected before you
start the first query:

$selected = Array();
$sql = SELECT id, category FROM categories, book_categories
 WHERE book_categories.bookID = '$bid' 
   book_categories.categories_id = categories.id;
if ( ( $results = mysql_query($sql, $db) ) )
{
while ( $row = mysql_fetch_assoc($results) )
{
$selected[] = $row['id'];
}
}

 Problem #2) in the second query, the selected is in the source code but
 it is not highlited. Several times I did get the categories highlighted,
 but I could never catch what it was that made it work. When I had the
 $id problem, i was trying this code from Yuri (but I don't understand
 where he got the $id from ) :
 

The HTML you generate in the selected case is not quite right - you should have
quotes around the value attribute's value, and you missed a closing '' off
the option tag...

while ( $row = mysql_fetch_assoc($results) )
{
if (in_array($row['id'], $selected))
{
echo option value=', $row['id'], ' selected='selected' ,
$row['category'], /optionbr /;
}
else
{
echo option value=, $row['id'], , $row['category'], /optionbr 
/;
}
}

More succinctly:

while ( $row = mysql_fetch_assoc($results) )
{
$sel = in_array($row['id'], $selected) ? selected='selected':;
echo option value='{$row['id']}' $sel{$row['category']}/optionbr /;
}

Unless the code is seriously performance critical, I still think variable
interpolation is nicer to read than all those quotes and commas, and it keeps
the HTML structure together better...


Good luck

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: aesthetic beauty in conception, execution

2009-06-18 Thread Peter Ford
PJ wrote:
 I just thought I would share a revelation.
 Someone just pointed me to a site that IMHO is superb for elegance of
 artistic design and programming.
 I was blown away.
 http://www.apfq.ca
 You won't regret it. 8-)
 

Il y a seulement une problème - je ne lis pas Française...

I18N - it's important, you know...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Search/Replace in entire database?

2009-06-15 Thread Peter Ford
Chris Payne wrote:
 Hi everyone,
 
 I am in the middle of creating an editor where you can search and
 replace on an individual column in a single table then I came across
 something I need to be able to do but not sure how.
 
 Is it posible (And if so please how :-) to search an entire database
 and all tables within a database and do a find/replace on keywords
 without having to specify each table/column within that table?
 
 The people I am working for have made some big changes and one of them
 is changing the names of one of their products, but this product name
 appears EVERYWHERE in many tables and in lots of different column
 names, and it would save so much time if I could do a single query
 that would just search EVERYTHING within the database.
 
 Thanks for any advice you can give me.
 
 Regards
 
 Chris Payne

Chris,
This is not really a PHP question, is it? More like a question for the support
group that corresponds to your database software...

However, in my experience databases don't allow a cross-table update in a single
query - you won't be able to do it in one query.

You will either have to
1. work out which columns and tables contain the name
2. script a query to make the changes for each separately
3. test it on a backup version of the database
4. fix the bugs
5 run the script on the live database.

OR (possibly)

1. block access to the database (to prevent any changes while you are 
processing)
2. dump the whole DB to an SQL script
3. do a search and replace on the text of the SQL script
4. Drop the existing data and reload the database from your SQL dump
5. enable access again so that the users can find the (inevitable) mistakes.

These are both pretty time-consuming - sorry!

Then make a business case for the project of normalising the database, at least
with respect to the product names...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Dynamic Titles

2009-06-12 Thread Peter Ford
David Robley wrote:
 Austin Caudill wrote:
 
 Hello, im trying to make the CMS system im using more SEO friendly by
 giving each page it's own title. Right now, the system assigns all pages
 the same general title. I would like to use PHP to discertain which page
 is being viewed and in turn, which title should be used.

 I have put in the title tags the variable $title. As for the PHP im
 using, I scripted the following:

 $url = http://'.$_SERVER['SERVER_NAME']''.$_SERVER['REQUEST_URI']';
 switch ( $url )
 {
 default:
 $title = Photoshop tutorials, Flash tutorials, and more! Newtuts Tutorial
 Search; break;

 case $config[HTTP_SERVER]help.php :
 $title = Newtuts Help;
 break;
 }

 Right now, im getting this error:
 Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting
 T_STRING or T_VARIABLE or T_NUM_STRING in
 /home/a7201901/public_html/includes/classes/tutorial.php on line 803

 Can someone please help me with this?



 Thanks!
 I'm guessing that line 803 is
 
 $url = http://'.$_SERVER['SERVER_NAME']''.$_SERVER['REQUEST_URI']';
 
 which is full of mismatched quotes :-) Try any of
 
 $url = http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']};
 $url = http://.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
 $url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
 
 Cheers

Also the line:

  case $config[HTTP_SERVER]help.php :

probably won't work very well : should be either

  case $config[HTTP_SERVER].'help.php':

or

  case {$config[HTTP_SERVER]}help.php:

according to whether you like interpolation in quotes or not.


I recommend finding a development environment or editor that does syntax
highlighting - that would catch all of these problems before you even save the 
file.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: Any conflict with $_POST when 2 users concurrently submitting the same form using POST method?

2009-06-10 Thread Peter Ford
Keith wrote:
 Let's say user A and user B submitting purchase order form with
 order.php at the same time, with method=post action='confirmation.php'.
 
 (1)   Will $_POST['order'] submitted by user A replaced by
 $_POST['order'] submitted by user B, and the both user A  B getting the
 same order, which is made by user B? Why?
 
 (2)Since $_POST['xxx'] is superglobal array, will $_POST['order']
 read by users other than A  B? In shared hosting server environment,
 are all domains hosted within that server using the same $_POST array?
 Can $_POST array accessible by all domains even if not from the
 originating domain?
 
 Thx for clarification!
 
 Keith

Other posters have explained, but I'm not sure their explanations are clear.
Think of it like this:

User A posts to confirmation.php. When the server receives the request, it
starts up a Process and fills the $_POST array with whatever came in, then runs
confirmation.php with that information.

User B posts to confirmation.php. When the server receives the request, it
starts up a Process and fills the $_POST array with whatever came in, then runs
confirmation.php with that information.

The KEY thing is that the process in each case is entirely separate. Each makes
it's own copy of the script in its own bit of memory, and each has its own
version of $_POST in its own bit of memory.

The two posts can happen at the same time and they will still be completely
independent.

The fact that $_POST is called superglobal does not mean that it is shared by
separate requests - it is not even shared by requests in the same session. It
just means that it is already declared and you don't need to use the global
keyword to access it in your PHP pages.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Anyone know whats the best way to learn PHP

2009-06-01 Thread Peter van der Does
On Mon, 1 Jun 2009 15:43:21 +0500
Muhammad Hassan Samee hassansa...@gmail.com wrote:

 Hi
 
 Anyone know whats the best way to learn PHP? Every time I open an php
 book or look the codes online, my mind goes oh man, So many stuffs
 to learn and gets frustrated before i even start but on the other
 hand, I don't know why some how the brain keep on nagging me to learn
 PHP. I guess what's the fun way to learn php? Any good books?

Do you already code?
If so, just download something you are interested in, maybe WordPress
if you blog, with some plugins as those are most likely easier to read,
and look at the programs and try figuring out why things are working
they way they work.
I can't really remember how I started but I believe it was with
Postnuke a long time ago. I looked at the code, try to help fix bugs.

The best way to learn any language, computer or natural, is not by
sitting down and reading books, it's by actually programming/speaking
the language.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



[PHP] PHP class question

2009-05-21 Thread Peter van der Does
I have the following situation.

I wrote some software and split it up into functionality:

class core {
  function go{
  }
}

class A extends core {
  // PHP4 constructor
  function A {
$this-go();
  }

}

class B extends core {
}

In core I define functions and variables that are to be used
through out my program and to address those functions/variables I just
use $this- .

Now I ran into a situation where class A needs to be extended with
another class. This is not my choice, it's part of a framework I have
to use.

Currently I solved this by doing this:

class A extends framework_class {
  $var core;

  // PHP4 constructor
  function A {
$this-core = new core();
$this-core-go();
  }
}

The question I have, is this a good solution, is it the only solution
or are there different ways to tackle this?
As you might see it needs to run in PHP4.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

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



Re: [PHP] Re: PHP class question

2009-05-21 Thread Peter van der Does
On Thu, 21 May 2009 14:08:11 -0500
Shawn McKenzie nos...@mckenzies.net wrote:


 
 This doesn't make sense.  You say class A needs to be extended with
 another class, however what you show below is class A extending
 framework_class.
 

I worded it wrong, I apologize.
Class A needs to be an extension of the framework class.

-- 
Peter van der Does

GPG key: E77E8E98
IRC: Ganseki on irc.freenode.net
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



[PHP] Re: Parsing of forms

2009-05-18 Thread Peter Ford
Daniele Grillenzoni wrote:
 I noticed that php's way to fill $_GET and $_POST is particularly
 inefficient when it comes to handling multiple inputs with the same name.
 
 This basically mean that every select multiple in order to function
 properly needs to have a name ending in '[]'.
 
 Wouldn't it be easier to also make it so that any element that has more
 than one value gets added to the GET/POST array as an array of strings
 instead of a string with the last value?
 
 I can see the comfort of having the brackets system to create groups of
 inputs easily recognizable as such, while I can overlook the
 impossibility of having an input literally named 'foobar[]', having to
 add [] everytime there is a slight chance of two inputs with the same name.
 
 This sounds flawed to me, as I could easily append '[]' to every input
 name and have a huge range of possibilities unlocked by that.
 
 This can't be right. Or can it?

Isn't it ironic that a post about multiple form inputs is posted four times?
That's not a good way to make friends here, Daniele...

I really don't understand your complaint - in general if your form has multiple
inputs with the same name, then you either meant to do that, (like a multiple
select, in which case there's not really a big deal to add the []),
or it's wrong and wouldn't work as expected anyway.

You could append [] to every input - that would be lovely, but it would hide the
possibility that you mistakenly gave two inputs the same name.

It's true that every so often I can't work out why something is not posting an
array to PHP when I expected it to, and a look back to the form to find I'd
missed a [] on the name is the answer.

As I like to say in other areas of life (especially to my children), stop
whining and get on with it! ( sorry :) )

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Software to read/write Excel to CD?

2009-05-15 Thread Peter Ford
Matt Graham wrote:
 Ashley Sheridan wrote:
 Paul M Foster wrote:
 On Thu, May 14, 2009 at 03:22:12PM -0500, Skip Evans wrote:
 One of the things the other company said was possible, and I'm
 not familiar with... if I understand correctly, is to create a
 CD with not just an Excel spreadsheet, but software on that CD
 that when placed in another computer will open the
 spreadsheet, allow it to be modified and rewritten back to the CD.
 
 It has to be a CD-RW, the CD-RW has to be in UDF format, and the host
 machine has to be able to read and rewrite CD-RWs in UDF.  This is
 actually not that tough to arrange--it just has nothing to do with
 PHP.  'DozeXP should be able to do this, and Linux will do this if the
 right kernel options are on.  Don't know about OS X.
 
 Second, include some other program which
 would do the same thing. Good luck with that.
 
 OOO Calc, which should be just fine for basic tasks and is Free.
 
 And now the kicker-- write the spreadsheet back to CD. Okay, maybe, if
 it's a CD-RW. But who's going to pay attention to that little detail?
 And as far as I know, writing to a CD is far more complicated than
 writing to a hard drive. You can't overwrite data on a CD-RW.
 
 UDF, which has been a standard for quite some time, allows this.  The
 main thing you lose is some space on the CD-RW.
 
 I've never heard of anything like that, there are so many unknown
 variables that I would really feel for the poor team who had to take
 that project on!
 
 It sounds like whoever defined the requirements was trying to solve a
 problem in the wrong way.  Why drag physical media into this when you
 have the Net available?  And if the clients don't have the Net
 available, *why not*?
 


It *is* possible to be offline, and so far from anywhere that the only com links
are to satellites... (expensive).

I suspect that a USB key is a better option (and more physically portable) than
a UFB CD.

But why write an Excel spreadsheet - why not save the data in something more
portable like CSV that ExCel and read and write to once you are back at base?



-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP]Cannot output the same data from text file in PHP

2009-05-14 Thread Peter Ford
Moses wrote:
 Hi Folks,
 
 I have a written a script in PHP which outputs the result from a text file.
 The PHP script is as follows:
 
 ?php
 $alldata = file(result.txt);
 echo tabletrtd;
 foreach($alldata as $line_num = $line) {
 echo $line.br;
 }
 echo/td/tr/table;
 ?
 
 I have attached the result.txt file. However the output of the script is as
 follows:
 
 
 Query: 1 atggcaatcgtttcagcagattcgtaattcgagctcgcccatcgatcctcta 60
 
 Sbjct: 1 atggcaatcgtttcagcagattcgtaattcgagctcgcccatcgatcctcta 60
 
 which is not exactly  as in the result.txt file in that the pipelines
 are displaced.
 
 Any pointer to this problem shall be appreciated. Thanking you in advance.
 
 Moses
 

Not a PHP problem, but a HTML problem:
First, HTML compresses white space into just one space, so all of those leading
spaces on line 2 are lost.
Second, you are (probably) displaying using a proportionally-spaced font, so the
narrow pipeline characters take up less width than the letters.

So you need something like:
?php
$alldata = file(result.txt);
echo tabletrtd style='white-space: pre; font-family: monospace;';
foreach($alldata as $line_num = $line)
{
echo $line.\n;
}
echo/td/tr/table;
?


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] When is __destruct called on an object in $_SESSION ?

2009-05-14 Thread Peter Ford
I'm sure I've seen something about this before, but I can't find it:

I'm creating a file which needs to live for the duration of a session, and ONLY
the duration of the session.
I made a little call which holds the name of the file like this:
?php
class __TFR
{
private $file;
public function __construct()
{
$this-file = '/tmp/'.session_id().'.xml';
}

public function __get($name)
{
if ($name=='file') return $this-file;
}

public function __destruct()
{
@unlink($this-file);
}
}
?
So I create an instance of this object and I put a reference to the object in
the session:

?php
$_SESSION['TFR'] = new __TFR();
?

I was then expecting TFR::__destruct() to only be called when the session was
closed, with either a timeout, or a session_destroy() call.
But it looks like the object destructor is called at the end of every page.
Any ideas about working around that?


-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] When is __destruct called on an object in $_SESSION ?

2009-05-14 Thread Peter Ford
Stuart wrote:
 2009/5/14 Peter Ford p...@justcroft.com:
 I'm sure I've seen something about this before, but I can't find it:

 I'm creating a file which needs to live for the duration of a session, and 
 ONLY
 the duration of the session.
 I made a little call which holds the name of the file like this:
 ?php
 class __TFR
 {
private $file;
public function __construct()
{
$this-file = '/tmp/'.session_id().'.xml';
}

public function __get($name)
{
if ($name=='file') return $this-file;
}

public function __destruct()
{
@unlink($this-file);
}
 }
 ?
 So I create an instance of this object and I put a reference to the object in
 the session:

 ?php
$_SESSION['TFR'] = new __TFR();
 ?

 I was then expecting TFR::__destruct() to only be called when the session was
 closed, with either a timeout, or a session_destroy() call.
 But it looks like the object destructor is called at the end of every page.
 Any ideas about working around that?
 
 The destructor will be called at the end of each page request because
 the object in memory is destroyed.
 
 When the object is serialized you will get __sleep being called, and
 when it's unserialized you'll get __wakeup.
 
 There is no way to detect when a session is destroyed unless you
 implement your own session handler.
 
 -Stuart
 

Oh bother. I guess it's a consequence of the statelessness of the PHP engine.

I thought I might be able to set a flag in __sleep() to indicate that the
session had been serialised rather than destroyed, but __destruct() is called
before __sleep().

I will have to see whether it is worth coding a custom session handler or to
just let the disk fill up... :)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Re: Trying to create a colortable - what am I missing here?

2009-05-12 Thread Peter Ford
Thodoris wrote:
 
 דניאל דנון wrote:
 I've tried to make a color table, but I am missing something. not in the
 color-table-code itself, but in somewhere else... I just can't find...

 untested but try..

 // 4096*4096 = 16777216 = FF+1
 $im = imagecreate(4096, 4096);
 $white = imagecolorallocate($im, 0, 0, 0);
 $r = $g = $b = $x = $y =  0;
 $max = 255;
 while ($r = $max) {
   while ($g = $max) {
 while ($b = $max) {
   $n = imagecolorallocate($im, $r, $g, $b);
   imagesetpixel($im, $x, $y, $n);
   $x = $x == 4096 ? 0 : $x+1;
   $y = $y == 4096 ? 0 : $y+1;
   $b++;
 }
$b = 0;
$g++;
   }
   $g = 0;
   $r++;
 }
 header(Content-Type: image/png);
 imagepng($im);
 imagedestroy($im);


 
 Never used image manipulation with PHP but this is giving me a black image.
 


You probably need
$im = imagecreatetruecolor(4096,4096);

Also be aware that creating a truecolor image 4096 pixels square is going to
take a LOT of memory, and it will take a while to download to the client, AND it
is 4096 pixels square! That's a fair bit bigger than most screens...

I suspect the OP is going to have to rethink this...
-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Can not read write file from Desktop

2009-05-12 Thread Peter Ford
Thodoris wrote:
 
 hi
 I was trying to read a file from Desktop (Centos),

 Simply saying (php code file is in /var/www/html/ )

 if (file_exists(/root/Desktop/conf_files_linux))
 echo yes file is there;
 else
 echo no none;

 It gives me none.
 If i place conf_files_linux file in /var/www/html. i get yes...


 After checking log file i got

 [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)

 What  i need to do, so tht i can access files from outside?
 help pls

 thanx
   
 
 I assume that this running by the web server (/var/www/html) so a wild
 guess is that the user that your web server uses to run (usually apache
 or www) cannot access the Desktop directory. In order to use the suexec
 feature you need to configure it or else the web server user needs to
 have read/write rights to the directory you need to access like the
 Desktop.
 
 Though this not recommended. You could always run this script from
 command line being root or whatever user is the owner of the Desktop
 directory.  Read this if you are not aware of how this can be done:
 
 http://www.php.net/features.commandline
 

If the OP's system is set up properly, then nobody but root should be able to
read ANY of root's home directory, so the files will not be found.
For a start, one doesn't want config files in anyone's home directory if they
are for a system-wide server.
And one doesn't EVER want to have anything in /root that anyone but root needs
to access.
And one shouldn't be logged in as root unless one is doing a short-lived system
maintenance task: certainly one should not doing development work there...

I know it sounds dictatorial, but it's (part-way to) best practice...

Those config files should be in something like /etc/apache/extra, perhaps, if
they are not safe in the web root (which they probably are not, unless the web
server is configured to keep them safe)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] How to deal with identical fields in db

2009-05-06 Thread Peter Ford


tedd wrote: (and I added in some extra bits...)
 You need to normalize.
 
 Authors should have an unique id in an authors table. The authors table
 has all the specific information about authors, but not the books they
 have written.
 
 Books should have an unique id in a books table. The books table has all
 the specific information about books, but not the contributing authors.
 

Like the ISBN, for example - that should be unique enough for anyone...
I suppose if you deal in antique books, there might not be an ISBN.

 Then you connect the two tables with a Book-Author table that has only
 the id's of both -- no real need for any other information.
 

This also has the advantage that when you come to add new books by authors
already in the database, you only have to look the name up, and you can avoid
duplicating authors with misspelt names, etc.

You will have to allow for the case of a book with multiple authors, but that
should work out fine - you just have two (or more) records in the Book-Author
table to link the same book to several authors, and logic that watches out for
that when you extract the data.

 That way when you want to see all the books an author has written, then
 you pull out all the records that has the author's id and look up each
 book via the book id.
 
 Likewise, when you want to see all the authors who have contributed to a
 book, then you pull out all records that has the book's id and look up
 each author via their author id.
 
 Do you see how it works?
 
 Cheers,
 
 tedd
 

It always surprises me how many people need to have database normalisation
explained to them - it seems obvious to me... (and tedd, clearly!)

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] How to deal with identical fields in db

2009-05-06 Thread Peter Ford
tedd wrote:
 At 3:14 AM -0700 5/6/09, Michael A. Peters wrote:
 Peter Ford wrote:

 tedd wrote: (and I added in some extra bits...)
 You need to normalize.

 Authors should have an unique id in an authors table. The authors table
 has all the specific information about authors, but not the books they
 have written.

 Books should have an unique id in a books table. The books table has
 all
 the specific information about books, but not the contributing authors.


 Like the ISBN, for example - that should be unique enough for anyone...
 I suppose if you deal in antique books, there might not be an ISBN.

 Unfortunately sometimes an otherwise identical but different printing
 of the same book has different ISBN numbers. Sometimes the difference
 is hardback vs softcover, special edition, or just a reprint.

 The L.O.C. catalog number may be better, AFAIK there is typically only
 one LOC number per edition of a book. It is a good idea to record both
 (if both exist) and use an internally assigned substitute number when
 one, the other, or both don't exist (small run self published works
 often don't have a LOC number for example, if the author didn't want
 to pay for it).
 
 
 But for a database, a book identifier would probably be best (differing
 opinions on this) if it was simply an auto_increment unsigned integer
 primary key. A key that is generated upon entry of a book record.
 
 Certainly one can argue that using a different unique key might provide
 more information and make the table require one less field, but if one
 uses a primary key, then the field can be searched faster than using a
 ISBN or L.O.C., which may be duplicated, amended, or not even present.
 My thinking on this is a unique identifier for the book should not be
 tied to any attribute of the book, which may change, but rather
 something completely detached and artificial.
 
 Cheers,
 
 tedd
 

tedd,

That is, in fairness, probably what I'd do too: I might have the ISBN or LOC
number as a detail field in the book record, and have it available for look-ups,
but the primary key would just be a sequence number generated automatically.
Same with authors, just a sequence number for the key. (I am not a number, I am
a free man...)

These things do not need to be visible to the user. Just an implementation
detail, nothing to see here... :)

Cheers
Pete

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: graphical integrated development environment recommendations?

2009-05-05 Thread Peter Ford
Adam Williams wrote:
 With the wide range of users on the list, I'm sure there are plenty of
 opinions on what are good graphical IDE's and which ones to avoid.  I'd
 like to get away from using notepad.exe to code with due to its
 limitations.  Something that supports syntax/code highlighting and has
 browser previews would be nice features.  I'm looking at Aptana
 (www.aptana.com) but it seems like it is more complicated to use then it
 should be.  Either Linux or Windows IDE (i run both OSes)
 recommendations would be fine.
 

Netbeans: works on Windows or Linux (or OSX, if you're that way inclined), and
it's free.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] object literals

2009-05-01 Thread Peter Ford
Richard Heyes wrote:
 Hi,
 
$x = (object) array('a'=1, 'b'=3, ...);

 which works but isn't very lovely. it's neater in, for example, javascript.
 
 Well, you could wrap it up in a function to make it a bit lovelier. Eg:
 
 $foo = createObject(array('key' = 'value'));
 
 It's not great, but PHP doesn't have a object literal syntax AFAIK.
 
You could use JSON,

$foo = json_decode('{a:1,b:3}');

but I guess that's not much better than Richard's suggestion.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Re: error in printer_open function

2009-04-28 Thread Peter Ford
AYAN PAL wrote:
 hi,
 i am using local server to print a simple text
 i config the php.ini file as 
 ;extension=php_printer.dll
 added in the extension list
 and add 
 [printer]
 printer.default_printer = Send To OneNote 2007
 in this file
 
 and write a sim ple page as-
 
 
 
 
 
 Prabal Cable Network
 
 
 
 
 
 

The ; at the start of the configuration line in php.ini is a comment 
character...
Remove that, restart the web server, and you might see things working better.

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Multiple return statements in a function.

2009-04-23 Thread Peter van der Does
I tend to put my return value in a variable and at the end of the
function I have 1 return statement.
I have seen others doing returns in the middle of the function.

Example how I do it:
function check($a) {
  $return='';
  if ( is_array( $a ) ) {
$return='Array';
  } else {
$return='Not Array';
  }
  return $return;
}

Example of the other method:
function check($a) {

  if ( is_array( $a ) ) {
return ('Array');
  } else {
return ('Not Array');
  }
}

What is your take? And is there any benefit to either method?


-- 
Peter van der Does

GPG key: E77E8E98
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Jabber ID: pvanderd...@gmail.com

GetDeb Package Builder
http://www.getdeb.net - Software you want for Ubuntu

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



Re: [PHP] Generate XHTML (HTML compatible) Code using DOMDocument

2009-04-14 Thread Peter Ford
Michael Shadle wrote:
 On Mon, Apr 13, 2009 at 2:19 AM, Michael A. Peters mpet...@mac.com wrote:
 
 The problem is that validating xhtml does not necessarily render properly in
 some browsers *cough*IE*cough*
 
 I've never had problems and my work is primarily around IE6 / our
 corporate standards. Hell, even without a script type it still works
 :)
 
 Would this function work for sending html and solve the utf8 problem?

 function makeHTML($document) {
   $buffer = $document-saveHTML();
   $output = html_entity_decode($buffer,ENT_QUOTES,UTF-8);
   return $output;
   }

 I'll try it and see what it does.
 
 this was the only workaround I received for the moment, and I was a
 bit afraid it would not process the full range of utf-8; it appeared
 on a quick check to work but I wanted to run it on our entire database
 and then ask the native geo folks to examine it for correctness.

I find that IE7 (at least) is pretty reliable as long as I use strict XHTML and
send a DOCTYPE header to that effect at the top - that seems to trigger a
standard-compliant mode in IE7.
At least then I only have to worry about the JavaScript incompatibilities, and
the table model, and the event model, and 

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



[PHP] Larger fonts...

2009-04-08 Thread Peter Ford
Patrick,

The reason you think the fonts are too small is that you have (un)zoomed the
screen at some point. The proportions of the centre white panel to the side bars
is wrong.
Measuring your screenshots, and assuming you had a full-screen browser window at
1680x1050 resolution (what your monitor does), I work out that the white section
of the screen is only around 800 pixels wide - it is defined to be 1000 pixels
wide at normal magnification. Measuring the icons suggests that your screen is
showing them at 42 pixels, while they are supposed to be 56 pixels. Overall,
your seeing the whole thing at 80% full size - no wonder the fonts look small!

The fonts and icon sizes haven't changed for about a year, and you haven't
really complained before.

In addition, you are using a pretty large screen - the pages are designed to
work on a 1024x768 screen as a minimum. Making the fonts larger would
drastically reduce the amount of information displayed vertically - it's already
pretty tight on some of the design screens.

So, I'll ignore the calls for bigger fonts and icons.

The button icons may also look better at full size, but the main problem is that
they need to be properly designed. Replacing them with just words is not very
good - it makes them all different sizes, which messes up the layout.
I could remove the shaded background and see if that helps.

Other points I will work on.

Cheers

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



Re: [PHP] Larger fonts...

2009-04-08 Thread Peter Ford
Tom,

You're right - I tried to catch it before it went, but just too late!

To the list - please ignore the message Tom refers to  - it's not too
commercially sensitive, at least.

I probably need more coffee before fielding bug reports in the morning.


Cheers
Pete

Tom Chubb wrote:
 Pete,
 Before you get slated by the list, I'm guessing you meant to send this
 to someone else?
 (It came to me via the PHP-General Mailing List.
  
 Tom
 
 2009/4/8 Peter Ford p...@justcroft.com mailto:p...@justcroft.com
 
 Patrick,
 
 The reason you think the fonts are too small is that you have
 (un)zoomed the
 screen at some point. The proportions of the centre white panel to
 the side bars
 is wrong.
 Measuring your screenshots, and assuming you had a full-screen
 browser window at
 1680x1050 resolution (what your monitor does), I work out that the
 white section
 of the screen is only around 800 pixels wide - it is defined to be
 1000 pixels
 wide at normal magnification. Measuring the icons suggests that your
 screen is
 showing them at 42 pixels, while they are supposed to be 56 pixels.
 Overall,
 your seeing the whole thing at 80% full size - no wonder the fonts
 look small!
 
 The fonts and icon sizes haven't changed for about a year, and you
 haven't
 really complained before.
 
 In addition, you are using a pretty large screen - the pages are
 designed to
 work on a 1024x768 screen as a minimum. Making the fonts larger would
 drastically reduce the amount of information displayed vertically -
 it's already
 pretty tight on some of the design screens.
 
 So, I'll ignore the calls for bigger fonts and icons.
 
 The button icons may also look better at full size, but the main
 problem is that
 they need to be properly designed. Replacing them with just words is
 not very
 good - it makes them all different sizes, which messes up the layout.
 I could remove the shaded background and see if that helps.
 
 Other points I will work on.
 
 Cheers
 
 --
 Peter Ford  phone: 01580 89
 Developer   fax:   01580 893399
 Justcroft International Ltd., Staplehurst, Kent
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 -- 
 Tom Chubb
 t...@tomchubb.com mailto:t...@tomchubb.com | tomch...@gmail.com
 mailto:tomch...@gmail.com
 07912 202846


-- 
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

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



[PHP] Re: PHP class or functions to manipulate PDF metadata?

2009-04-07 Thread Peter Ford
O. Lavell wrote:
 Peter Ford wrote:
 
 O. Lavell wrote:
 
 [..]
 
 Any and all suggestions are welcome. Thank you in advance.

 So many people ask about manipulating, editing and generally processing
 PDF files. In my experience, PDF is a write-once format - any
 manipulation should have been done in whatever source generated the PDF.
 I think of a PDF as being a piece of paper: if you want to change the
 content of a piece of paper it is usually best to chuck it away and
 start again...

 Even more so, this would apply to the PDF metadata: metadata is supposed
 to describe the nature of the document: it's author, creation time etc.
 That sort of data should be maintained with the document and ideally not
 changed throughout the document's lifetime (like the footer, or
 end-papers in a physical book)
 
 Thank you very much for your reply. And it's not that I don't agree with 
 you. Because I do, completely.
 
 However...
 
 PDFs often come from sources that can't be bothered to fill in the 
 relevant fields correctly, completely, or at all. For those cases I would 
 like the users of my application to be able to correct the values found 
 in the metadata. Upload the PDF, get a nice little HTML form with 4 or 5 
 values to review or edit. That sort of thing.
 
 I do accept that the metadata should be machine-readable: that part of
 your project is reasonable and I'm fairly sure that ought to be possible
 with something simple. The best bet I found so far is PDFTK
 (http://www.pdfhacks.com/pdftk/) which is a command-line tool that you
 could presumably call with exec or whatever...
 
 Like I said, this is what I am already doing with the pdfinfo utility 
 from xpdf.

Sorry - I guess I didn't read that bit carefully enough...

 
 But now that you mentioned pdftk... I just tried it and it does seem to 
 come close to what I want. It is capable of writing a new PDF with the 
 contents of an existing one, with new metadata fed as a text file. So it 
 shouldn't be very hard to write a little PHP around that process.
 
 Now I need to think a bit more about this approach. Perhaps it can be 
 implemented using only pure PHP, after all. But for the time being, pdftk 
 will do.
 
 So thank you again for pushing me in that direction, even if 
 unintentionally and despite the fact that what I am doing goes against 
 your judgement ;)
 

As I know only too well, you can't always choose your customers (especially if
they choose you...) and you certainly can't control all of the sources of data
you have to deal with!
I have spent many hours/days/possibly longer hacking through files that are in
one form to get data into another, and PDF is the one that always makes me
nervous :(
My judgement is certainly not final, or even particularly important: if I had
time I would also look into at least getting the metadata with pure PHP.

Good luck...

-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



<    1   2   3   4   5   6   7   8   9   10   >