php-general Digest 23 Mar 2010 14:50:12 -0000 Issue 6655

Topics (messages 303120 through 303142):

PHP to access shell script to print barcodes
        303120 by: Rob Gould
        303125 by: Jochem Maas
        303137 by: Richard Quadling

Re: Will PHP ever "grow up" and have threading?
        303121 by: Tommy Pham
        303122 by: Teus Benschop
        303123 by: Larry Garfield
        303124 by: Jochem Maas
        303126 by: Rene Veerman
        303127 by: Tommy Pham
        303128 by: Tommy Pham
        303129 by: Per Jessen
        303130 by: jose javier parra sanchez
        303133 by: Rene Veerman
        303136 by: David McGlone
        303138 by: Richard Quadling
        303140 by: Michael A. Peters

Re: Filtering all output to STDERR
        303131 by: Marten Lehmann
        303135 by: Peter Lind

constants STDOUT, STDERR, STDIN not working in 5.2.x?
        303132 by: Marten Lehmann
        303134 by: Jan G.B.
        303141 by: Daniel Egeberg
        303142 by: Jan G.B.

Re: another question on setting include paths for a project
        303139 by: Robert P. J. Day

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
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.
B)  Can someone try following the 5 steps listed on the website 
(http://blog.maniac.nl/2008/05/28/creating-lto-barcodes/) and tell me if you 
have any better luck?  It doesn't really sound all that difficult.  I'm hosting 
this on Dreamhost, and I'm not sure if there's some sort of permissions/shell 
exec feature I need to make this work.  I'm not convinced that I really have a 
functioning Postscript file.  My Mac renders Postscript files automatically 
after downloading with the Preview app, and I'm not seeing any valid data 
returned.



--- End Message ---
--- Begin Message ---
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.

--- End Message ---
--- Begin Message ---
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 moveto (000115L3) (includetext height=0.55) code39 barcode
220 390 moveto (000116L3) (includetext height=0.55) code39 barcode
220 320 moveto (000117L3) (includetext height=0.55) code39 barcode
220 250 moveto (000118L3) (includetext height=0.55) code39 barcode
220 180 moveto (000119L3) (includetext height=0.55) code39 barcode
220 110 moveto (000120L3) (includetext height=0.55) code39 barcode
220 40 moveto (000121L3) (includetext height=0.55) code39 barcode
410 740 moveto (000122L3) (includetext height=0.55) code39 barcode
410 670 moveto (000123L3) (includetext height=0.55) code39 barcode
410 600 moveto (000124L3) (includetext height=0.55) code39 barcode
410 530 moveto (000125L3) (includetext height=0.55) code39 barcode
410 460 moveto (000126L3) (includetext height=0.55) code39 barcode
410 390 moveto (000127L3) (includetext height=0.55) code39 barcode
410 320 moveto (000128L3) (includetext height=0.55) code39 barcode
410 250 moveto (000129L3) (includetext height=0.55) code39 barcode
410 180 moveto (000130L3) (includetext height=0.55) code39 barcode
410 110 moveto (000131L3) (includetext height=0.55) code39 barcode
410 40 moveto (000132L3) (includetext height=0.55) code39 barcode


No idea if that is accurate or not. If you can run the script by hand
once to confirm, then
-- 
-----
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=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--- End Message ---
--- Begin Message ---
On Mon, Mar 22, 2010 at 7:40 PM, Adam Richardson <simples...@gmail.com> wrote:
> On Mon, Mar 22, 2010 at 10:23 PM, Daevid Vincent <dae...@daevid.com> wrote:
>
>> > >>>> Is this a case of "it's too hard"?
>> >
>> > Subscribe to internals. Read the archives. The truth is out there.
>>
>> I have Googled a while on this and don't see much of anything about "PHP
>> threading" of use. Just a bunch of people desperately wishing for this
>> feature and trying to hack some way of doing it. Hence my asking here.
>>
>> >>>> "foo($set_this_parameter=$bar);" bull$hit??! (there is NO
>> >>> reason NOT to let
>> >>>
>> >>>> the developer choose WHICH of the list of parameters they
>> >>> want to set in a
>>
>> > There are reasons. You would know this if you had done the legwork
>> > before opening your mouth and letting crap fall out.
>>
>> I have researched this. (http://bugs.php.net/bug.php?id=47331) The only
>> reason I see given for this lack of feature is "it was decided that you can
>> pass an array parameter instead". This isn't a solution, it's a hack. AND
>> it only works if you are creating a new function or adding to a function.
>> It does nothing for existing functions that have many parameters. Why
>> wouldn't you want to make an already amazing language better and more
>> flexible. I honestly see zero downside or complication to this. In fact I
>> am working on a site coded in PHP by Python people, and often find exactly
>> what I suggest in the code because Python can do this. Ironically it works
>> by dumb luck b/c PHP ignores the assignment or something and so the
>> parameters just happened to line up. Even C# can do this.
>>
>> > >>>> many parameters and you can't overload functions like you
>> > >>> can in Java or
>> >
>> > PHP is NOT Java.
>> >
>> > >>>> other typed languages)
>> >
>> > Nor is it OTHER types languages.
>>
>> Uh. Pretty much EVERY other major language has threading. C++, C#, Java,
>> Ruby, Python and even the archaic Perl.
>>
>> I KNOW PHP is not Java. That's why I use it. That doesn't take away from
>> the fact it still needs to have threading to compete as a serious language
>> if you ever want to do anything more than web pages.
>>
>> > > You could implement the features yourself.
>> >
>> > Damn, Mr McGlone beat me to it :)
>>
>> That's such a STUPID retort I'm so sick of hearing from the FOSS community.
>> "build it yourself uh huhh uhhh huhhh". Obviously I'm not a low-level C/C++
>> coder -- that's WHY I use PHP. :-\ So, you just stay content with the
>> status quo. I will continue to ask for features to enhance the language.
>> They may fall on deaf ears, but sometimes... just sometimes... The squeaky
>> wheel get's the grease.
>>
>> > When you set the subject line of your rant to something like
>> > "Will PHP
>> > ever 'grow up'", I expect your argument to at least be rationale,
>> > logical, and quite possibly contain a patch. It's called
>> > "open source"
>> > because you too can make changes.
>>
>> It was logical and rational. I gave examples of why threads are needed in
>> PHP and why it's STILL considered a sub-language by many enterprise level
>> people, and also why it will NEVER be used for anything more than web pages
>> until threading is implemented.
>>
>> By "grow up", I mean exactly that. PHP needs to be considered a contender
>> and an equal to other enterprise level languages, not this little amateur
>> language that script kiddies use. While we here may know the power and
>> virtues of the language, I assure you that most of the world still views it
>> as a toy language. And spare me your examples of Google or Twitter or some
>> other large site that uses it. I'm saying, as a whole, it is still viewed
>> that way by most enterprises. But more importantly, it is IMPOSSIBLE for
>> PHP to be used in writing daemons or anything of any complexity save web
>> pages. This is one reason why Python is used for most of your Linux
>> scripts. Or why Java/C# are used for applications. And honestly, I'd say a
>> big reason that Rails has taken off even.
>>
>> You're all getting hung up on my little paragraph rant about the parameter
>> feature that is desperately missing from PHP too. I'm sorry I threw that
>> into the mix, I didn't realize it would confuse you all so much from the
>> main topic.
>>
>> Clearly you had nothing of value to add to the question(s) and only wished
>> to chastise me for using harsh words which offended your delicate ears. I'm
>> sorry, but when a project like PHP is made for the masses to use, and when
>> many people are asking for useful, sane and reasonable features, and the
>> internal devs simply dismiss them because they don't feel like implementing
>> something (or maybe they don't have the skills to), I call bullshit. And
>> then to hide under the safety net of "well then submit a patch" is just
>> cowardice. I suspect that even *if* I submitted the perfect patch, that the
>> internal devs would not put it in the main tree because THEY are
>> fundamentally against the idea, so it's a Catch22. You need their blessing
>> either way. As John Acton said, "Power corrupts; absolute power corrupts
>> absolutely".
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> Hi Deavid,
>
> At this point, I find that when I need threading capabilities, I switch over
> to developing with C# or Java most of the time, but it would be nice to stay
> in PHP for these tasks (I, too, looked into the pcntl technique and that
> just didn't seem like the right way to handle them.)
>
> Yes, your last paragraph was a doozy, and few will accuse you of long-term
> political aspirations in any arena ;)  However, I will go on record saying
> that having threading would be a feature I'd very much appreciate, and I
> believe it would strengthen the value proposition of PHP in the
> ever-changing world of development.
>
> Adam
>
> --
> Nephtali:  PHP web framework that functions beautifully
> http://nephtaliproject.com
>

Threading is one of the 2 two main reasons why I moved to Java &
asp.net (C#).  I've built a PHP based web crawler about 10 years ago.
I ran into some problems: cookies, form handling and submission,
threading, and application variables.  I later found some solutions
for cookies, form handling & submission.  But no solution for
threading and application variables.  Thus the move.  Here's a simple
example of one of the many uses for threading.  For an e-commerce
site,  when the shopper requests for a category (ID), you can have a
thread to get all subcategories for that category, another thread to
get any assigned products,  another thread to fetch all manufacturers
listed under that category, another thread to fetch any filters (price
ranges, features, specs, etc) set by the store owner that would fall
under that category, etc...  versus what PHP currently doing now:
fetch subcategories, then fetch assigned products, then fetch
manufacturers, etc....  Performance would increase ten fold because of
parallel (threading) operations versus serial operations.  Add that to
application variable (less memory usage and CPU cycles due to
creating/GC of variables that could be used for an entire application
regardless of requests & sessions), you have an excellent tool.

Regards,
Tommy

--- End Message ---
--- Begin Message ---
There can be, and there are, differences between the languages. There
are so many languages out there, and it works like a market place. If
you like the language, use it. It it fails to do what you want, you
switch to another one. There is no need to beg the php developers to
implement anything, as long as you can switch to another language. Teus.

--- End Message ---
--- Begin Message ---
On Monday 22 March 2010 10:51:14 pm Tommy Pham wrote:
> Threading is one of the 2 two main reasons why I moved to Java &
> asp.net (C#).  I've built a PHP based web crawler about 10 years ago.
> I ran into some problems: cookies, form handling and submission,
> threading, and application variables.  I later found some solutions
> for cookies, form handling & submission.  But no solution for
> threading and application variables.  Thus the move.  Here's a simple
> example of one of the many uses for threading.  For an e-commerce
> site,  when the shopper requests for a category (ID), you can have a
> thread to get all subcategories for that category, another thread to
> get any assigned products,  another thread to fetch all manufacturers
> listed under that category, another thread to fetch any filters (price
> ranges, features, specs, etc) set by the store owner that would fall
> under that category, etc...  versus what PHP currently doing now:
> fetch subcategories, then fetch assigned products, then fetch
> manufacturers, etc....  Performance would increase ten fold because of
> parallel (threading) operations versus serial operations.  Add that to
> application variable (less memory usage and CPU cycles due to
> creating/GC of variables that could be used for an entire application
> regardless of requests & sessions), you have an excellent tool.
> 
> Regards,
> Tommy

Threading is also much more difficult to program for safely, because thread 
order is non-deterministic.  Do you really want to unleash hoards of 
marginally competent programmers on a threaded enviornment? :-)

Also, the architecture you describe above is fine if you're scaling a single 
server really big.  PHP is designed to scale the other direction: Just add 
more servers.  There's no data shared from one request to another, so there's 
no need to share data between web heads.  Throw a load balancer in front of it 
and spin up as many web servers as you need.  

The "shared nothing" design is very deliberate.  It has design trade-offs like 
anything else.

PHP is a web-centric language.  It's not really intended for building tier-1 
daemon processes, just like you'd be an idiot to try and code your entire web 
app in C from the start.

--Larry Garfield

--- End Message ---
--- Begin Message ---
Op 3/23/10 12:02 AM, Daevid Vincent schreef:
> I've been using PHP for a decade or so (since PHP/FI) and love it. The one

<snip />

well they certainly ripped you a new one didn't they :)

why no threads? shared-nothing architecture, that's very deliberate, it has draw
backs as well as advantages, either way you have to understand the reasoning and
how to leverage it. shared-nothing obviously doesn't lend itself to writing fast
daemonized code, then again it wasn't meant to.

I'd say that named function/method parameters would be a nice addition though -
although having said that a decent IDE with code completion (DocBlocks) and 
well commented,
well structured code mitigate the issue, for me anyway.

> 
> 


--- End Message ---
--- Begin Message ---
ExecSum:
*   +1 for better threading features in PHP.
*   overloading = inheritance?
*   listreaders plz allow ppl to vent some frustration without
starting a flamewar.

Threading can be implemented in PHP with an
fopen('http://yourserver.com/url')->fread()_all_threads+usleep(50ms)->fclose()+process
loop.

My own newsscraper threads well like this.
The central script figures out what sites to scrape, and the treaded
subsystem makes sure 1 page per site per N seconds is retrieved.

But i've yet to find a way to keep global objects in memory between
http requests, outside $_SESSION, which i believe is just stored to-
and loaded from disk between http requests.

However, now that i think of it, you could have large pieces of
software stay in memory in a single php script that runs forever and
reads commands (as arrays) out of files (on memory disk?) (put there
by "thread-scripts") and [the "forever running script"] outputs to
stdout, which is caught by the thread-scripts, then passed back to the
thread-caller via fread().
I usually use json for such constructs.
But it's a total hack of course, and i have no idea about performance
issues or even timing bugs. it's "theoretically possible"..

>there is NO reason NOT to let
> the developer choose WHICH of the list of parameters they want to set in a
> function/method call aside from being stubborn! Especially when there are
> many parameters and you can't overload functions like you can in Java

well you could shove all the params in an array, then shove that to
the function called, _or_ a preparatory function that calls the old
function.

as for overloading functions, i think with a bit of cleverness you can
come up with a class / set of functions that simulate overloading of
functions and even inheritance. i for a fact simulate polymorphism
with $functionName_fromPluginX ($params).
i smell all the ingredients that would allow you to overload functions
in php aswell. you'd just have to call things a bit differently,
perhaps like
$var = $overloadingManager->call ('functionName',
'context(object-instance-id)', $param1, $param2).

Better yet; aren't OOP's (and php5's) inheritance features (for
classes) similar to functions overloading? k, it forces you to group
such functions into an object, and derivations into subobjects, but
that's not a show-stopper at all.. You can always ignore the object
boundary and have 1 object-tree for all functions that require
overloading.


& lastly, about the politics of this mail-thread;
imo, it's the ones who "open the counterattack" who start the
flamewar, out of something that is clearly in this case just venting
some frustration with at least partially valid reasons..

imo, it would be wiser to have offered the guy some actual tips and/or
a casual "hey, you could've phrased it friendlier, given the fact that
php costs nothing and all, dude", rather than grabbing the
flamethrower and setting it to vaporize.

On Tue, Mar 23, 2010 at 1:02 AM, Daevid Vincent <dae...@daevid.com> wrote:
> I've been using PHP for a decade or so (since PHP/FI) and love it. The one
> problem that seems to always keep coming back on enterprise level projects
> is the lack of threading. This always means we have to write some back-end
> code in Ruby or Java or C/C++ and some hacky database layer or DBUS or
> something to communicate with PHP.
>
> Will PHP ever have proper threading? It would sure let the language take
> the next logical leap to writing applications and daemons. I love the idea
> that Rails/Ruby have where you can just load objects in memory once and
> keep using them from page to page (this is NOT the same as a $_SESSION,
> it's way more flexible and powerful).
>
> But more importantly, in one application I'm working on, we need to connect
> to an Asterisk system for the IVR abilities. This means we have Ruby doing
> all that fun stuff and PHP doing the web stuff, but we're also duplicating
> a LOT of work. Both Ruby AND PHP now have to have ORMs for the user who's
> calling in, advertisements served, products shown, etc. We could have used
> Rails for the web portion, but I want to stay with PHP and I'm sure I don't
> have to explain to you PHPers why that is. Without threads, PHP just isn't
> even an option or only one user would be able to call in at a time.
>
> The pcntl stuff is not feasible. It's a hack at best. Spawning multiple
> scripts is also a recipie for disaster.
>
> When will the PHP core-devs (Zend?) realize that PHP is much more than a
> hook to a database. It's much more than web pages.
>
> Is this a case of "it's too hard"? Or is it a case of PHP core developers
> just being douche-bags like they are about the whole
> "foo($set_this_parameter=$bar);" bull$hit??! (there is NO reason NOT to let
> the developer choose WHICH of the list of parameters they want to set in a
> function/method call aside from being stubborn! Especially when there are
> many parameters and you can't overload functions like you can in Java or
> other typed languages)
>
> As usual, I created a poll here too:
> http://www.rapidpoll.net/awp1ocy
>
> Past polls are below:
> http://www.rapidpoll.net/8opnt1e
> http://www.rapidpoll.net/arc1opy (although someone hacked this poll and
> loaded up the 76 votes like a little cheater)
>

--- End Message ---
--- Begin Message ---
On Mon, Mar 22, 2010 at 10:01 PM, Larry Garfield <la...@garfieldtech.com> wrote:
> On Monday 22 March 2010 10:51:14 pm Tommy Pham wrote:
>> Threading is one of the 2 two main reasons why I moved to Java &
>> asp.net (C#).  I've built a PHP based web crawler about 10 years ago.
>> I ran into some problems: cookies, form handling and submission,
>> threading, and application variables.  I later found some solutions
>> for cookies, form handling & submission.  But no solution for
>> threading and application variables.  Thus the move.  Here's a simple
>> example of one of the many uses for threading.  For an e-commerce
>> site,  when the shopper requests for a category (ID), you can have a
>> thread to get all subcategories for that category, another thread to
>> get any assigned products,  another thread to fetch all manufacturers
>> listed under that category, another thread to fetch any filters (price
>> ranges, features, specs, etc) set by the store owner that would fall
>> under that category, etc...  versus what PHP currently doing now:
>> fetch subcategories, then fetch assigned products, then fetch
>> manufacturers, etc....  Performance would increase ten fold because of
>> parallel (threading) operations versus serial operations.  Add that to
>> application variable (less memory usage and CPU cycles due to
>> creating/GC of variables that could be used for an entire application
>> regardless of requests & sessions), you have an excellent tool.
>>
>> Regards,
>> Tommy
>
> Threading is also much more difficult to program for safely, because thread
> order is non-deterministic.  Do you really want to unleash hoards of
> marginally competent programmers on a threaded enviornment? :-)

Marginally competent?  I think some, if not many, on this list will
disagree with that ;)

>
> Also, the architecture you describe above is fine if you're scaling a single
> server really big.  PHP is designed to scale the other direction: Just add
> more servers.  There's no data shared from one request to another, so there's
> no need to share data between web heads.  Throw a load balancer in front of it
> and spin up as many web servers as you need.

Load balancer is used when the server is overloaded with requests and
upgrade has reached it's limit.  That's not the same thing as a simple
request where multiple answers are needed as in my example.  If you're
thinking of implementing something like my example across multiple
servers (where each server will fetch an answer for a simple request)
via another method, then you're going to face similar issues as
threading ie session/request sync which is equivalent to thread
safety/sync/deadlock but now it's worse because it's spread across
network where performance issues comes in because internal system IO >
(network IO + internal system IO).

>
> The "shared nothing" design is very deliberate.  It has design trade-offs like
> anything else.
>
> PHP is a web-centric language.  It's not really intended for building tier-1
> daemon processes, just like you'd be an idiot to try and code your entire web
> app in C from the start.

Of course since C was engineered to create OSes and (text based) apps
when SMP/MC is unheard of.  But we're now in the digital era where
SMP/MC is very common place.  In fact, trying to buy a new
desktop/laptop now without a multicore becomes very difficult and
undesired.  Why not make use of the SMP/MC? :)  PHP seems strive and
somewhat 'imitate' languages like java & asp.net.  Not trying to go
off topice but for example: namespace (namespace in asp.net and
packages in java).  For many of us that don't use namespace now or
even when it's not yet implemented, we (PHP web app dev) already
implement our own version of it - subfolders.  So why not copy or
imitate the features that would be more beneficial if not more
usability ie threading?  PHP is already ahead of java & asp.net in
terms of generics, not strong typed.

Regards,
Tommy

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

--- End Message ---
--- Begin Message ---
Here's another analogy.  For those of us in the field long enough, we
see the power of AJAX and we use it in one form or another.  For the
newbies, they have yet to see it's power nor the requirements to
implement it.  Threading is similar to that.  It's not for everybody.
But for those of us that are ready and have need for it, we can
implement it IF IT'S THERE, which is the point of OP, although the way
he put it isn't exactly welcoming... perhaps he had a very long week
and it's just starting too.

--- End Message ---
--- Begin Message ---
Daevid Vincent wrote:

> I've been using PHP for a decade or so (since PHP/FI) and love it. The
> one problem that seems to always keep coming back on enterprise level
> projects is the lack of threading. This always means we have to write
> some back-end code in Ruby or Java or C/C++ and some hacky database
> layer or DBUS or something to communicate with PHP.

Use the right tool for the right job - PHP is a scripting/interpreted
language, it does not need threading (IMO of course).


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


--- End Message ---
--- Begin Message ---
Maybe that's what you are looking for : http://nanoserv.si.kz/

Not done with threads, but who cares ?

--- End Message ---
--- Begin Message ---
hmm i use scripted languages because i prefer and they allow/force
simple-to-read-code.

but that does not mean a scripted language can't evolve to expose
"complicated" code constructs like multi-threading and daemon-building
in a simple manner too.

i'd prefer it if a language like PHP can be used for other things
besides webserving too.
i also think at least some web-apps could benefit from multi-threading
and daemon-building.. particularly web-apps that deal with real-time
dataflows.

and btw, the distinction between compiled and scripted is not a hard
one anymore eh.. not with zend and that facebook php-compiler out
there.

On Tue, Mar 23, 2010 at 10:04 AM, Per Jessen <p...@computer.org> wrote:
> Daevid Vincent wrote:
>
>> I've been using PHP for a decade or so (since PHP/FI) and love it. The
>> one problem that seems to always keep coming back on enterprise level
>> projects is the lack of threading. This always means we have to write
>> some back-end code in Ruby or Java or C/C++ and some hacky database
>> layer or DBUS or something to communicate with PHP.
>
> Use the right tool for the right job - PHP is a scripting/interpreted
> language, it does not need threading (IMO of course).
>
>
> --
> Per Jessen, Zürich (9.4°C)
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
> > > You could implement the features yourself.
> >
> > Damn, Mr McGlone beat me to it :)
> 
> That's such a STUPID retort I'm so sick of hearing from the FOSS community.
> "build it yourself uh huhh uhhh huhhh". Obviously I'm not a low-level C/C++
> coder -- that's WHY I use PHP. :-\ So, you just stay content with the
> status quo. I will continue to ask for features to enhance the language.
> They may fall on deaf ears, but sometimes... just sometimes... The squeaky
> wheel get's the grease.

I didn't intend for my reply to sound nasty. After reading your OP, I see that 
you are a very experienced programmer and I meant for it as a suggestion.

-- 
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that 
I had nowhere else to go.

--- End Message ---
--- Begin Message ---
On 23 March 2010 00:02, Daevid Vincent <dae...@daevid.com> wrote:
> douche-bags

I think this is about the best way to get the wrong attention.

Not everyone has a sense of humour like yours.

Maybe no one has a sense of humour like yours.

Good luck.

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=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--- End Message ---
--- Begin Message ---
Rene Veerman wrote:


But i've yet to find a way to keep global objects in memory between
http requests, outside $_SESSION, which i believe is just stored to-
and loaded from disk between http requests.

You can store sessions in a cache and avoid the disk IO.

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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>

--- End Message ---
--- Begin Message ---
Hello,

I found different code examples like this, which use the file handle STDERR just like this:

<?php
fwrite(STDERR, "hello\n");
?>

Also, the PHP documentation of input/output streams (http://php.net/manual/de/wrappers.php.php) says:

"It is recommended that you simply use the constants STDIN, STDOUT and STDERR instead of manually opening streams using these wrappers."

I don't want to use the "php://stderr" wrapper, because this just creates a duplicate of the original STDERR handler and if I'm closing "php://stderr", the original STDERR still would exist.

When I'm using this code, I only get:

<b>Notice</b>: Use of undefined constant STDERR - assumed 'STDERR' in <b>/test.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>: fwrite(): supplied argument is not a valid stream resource in <b>/test.php</b> on line <b>4</b><br />

How can I access the original STDERR handle? The constant should be there, but does not exist.

regards
Marten

--- End Message ---
--- Begin Message ---
2010/3/23 Marten Lehmann <lehm...@cnm.de>

> Hello,
>
> I found different code examples like this, which use the file handle STDERR
> just like this:
>
> <?php
> fwrite(STDERR, "hello\n");
> ?>
>
> Also, the PHP documentation of input/output streams (
> http://php.net/manual/de/wrappers.php.php) says:
>
> "It is recommended that you simply use the constants STDIN, STDOUT  and
> STDERR instead of manually opening streams using these wrappers."
>
> I don't want to use the "php://stderr" wrapper, because this just creates a
> duplicate of the original STDERR handler and if I'm closing "php://stderr",
> the original STDERR still would exist.
>
> When I'm using this code, I only get:
>
> <b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in
> <b>/test.php</b> on line <b>4</b><br />
> <br />
> <b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource
> in <b>/test.php</b> on line <b>4</b><br />
>
> How can I access the original STDERR handle? The constant should be there,
> but does not exist.
>
> regards
> Marten
>
>
Hi,

I can reproduce it with some differences. Check this out:

 $ php --version
PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: Jan  6 2010
22:56:44)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

$ php 1>/dev/null             # note that the PHP error messages are
displayed on STDOUT - I don't show them with "1>/dev/null"
<?
$x = fopen('php://stderr', 'r'); fwrite($x, "test\n"); fclose($x);
$x = fopen(STDERR, 'r'); fwrite($x, "test2\n"); fclose($x); ?>
------------
<?
fwrite(STDERR, "test3\n");
fwrite ('php://stderr', "test4");
?>
-----------

Result:

test


--------

So my assumption is, that the quoted recommendation is outdated / wrong.

Regards


PS: PHP reports this when giving the constant STDERR:
  Warning: fopen(STDERR): failed to open stream: No such file or directory
  Warning: fwrite(): supplied argument is not a valid stream resource

--- End Message ---
--- Begin Message ---
On Tue, Mar 23, 2010 at 11:47, Marten Lehmann <lehm...@cnm.de> wrote:
> Hello,
>
> I found different code examples like this, which use the file handle STDERR
> just like this:
>
> <?php
> fwrite(STDERR, "hello\n");
> ?>
>
> Also, the PHP documentation of input/output streams
> (http://php.net/manual/de/wrappers.php.php) says:
>
> "It is recommended that you simply use the constants STDIN, STDOUT  and
> STDERR instead of manually opening streams using these wrappers."
>
> I don't want to use the "php://stderr" wrapper, because this just creates a
> duplicate of the original STDERR handler and if I'm closing "php://stderr",
> the original STDERR still would exist.
>
> When I'm using this code, I only get:
>
> <b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in
> <b>/test.php</b> on line <b>4</b><br />
> <br />
> <b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource
> in <b>/test.php</b> on line <b>4</b><br />
>
> How can I access the original STDERR handle? The constant should be there,
> but does not exist.
>
> regards
> Marten

These I/O streams are only present in the CLI SAPI.

-- 
Daniel Egeberg

--- End Message ---
--- Begin Message ---
2010/3/23 Daniel Egeberg <degeb...@php.net>

> On Tue, Mar 23, 2010 at 11:47, Marten Lehmann <lehm...@cnm.de> wrote:
> > Hello,
> >
> > I found different code examples like this, which use the file handle
> STDERR
> > just like this:
> >
> > <?php
> > fwrite(STDERR, "hello\n");
> > ?>
> >
> > Also, the PHP documentation of input/output streams
> > (http://php.net/manual/de/wrappers.php.php) says:
> >
> > "It is recommended that you simply use the constants STDIN, STDOUT  and
> > STDERR instead of manually opening streams using these wrappers."
> >
> > I don't want to use the "php://stderr" wrapper, because this just creates
> a
> > duplicate of the original STDERR handler and if I'm closing
> "php://stderr",
> > the original STDERR still would exist.
> >
> > When I'm using this code, I only get:
> >
> > <b>Notice</b>:  Use of undefined constant STDERR - assumed 'STDERR' in
> > <b>/test.php</b> on line <b>4</b><br />
> > <br />
> > <b>Warning</b>:  fwrite(): supplied argument is not a valid stream
> resource
> > in <b>/test.php</b> on line <b>4</b><br />
> >
> > How can I access the original STDERR handle? The constant should be
> there,
> > but does not exist.
> >
> > regards
> > Marten
>
> These I/O streams are only present in the CLI SAPI.
>
> --
> Daniel Egeberg
>
> Please confirm that the code of my previous replay on this topic (executed
via php-cli) does not print out "test2" or "test3". The constant is present
but doesn't work as supposed.

Regards

--- End Message ---
--- Begin Message ---
On Mon, 22 Mar 2010, Nilesh Govindarajan wrote:

> What I do is, set the include path in the top-level bootstrapper.
>
> /bootstrap.php:
>
> set_include_path(dirname(__FILE__) . '/lib' . PATH_SEPARATOR .
> get_include_path());
>
> Then I load the autoloader from /lib/autoload.php at the time of bootstrap.
>
> /lib contains others /lib/Common, /lib/Util, etc.
>
> So when I say "new Common_Form();", it will include /lib/Common/Form.php

  not bad, i'll look at that more closely.  but let me mention a
wrinkle i mentioned before and expand on it so folks can see what i'm
trying to do and why i was suggesting the strategy i did.

  as i said, something i've used before (in admittedly non-PHP
projects) was to require developers who checked out the code base to
set a single env variable (say, PROJ_DIR) to point at the location of
the checkout.  while someone earlier suggested that was "overkill,"
this approach had a major benefit for me.

  in both that earlier project and in this current PHP project, there
was the possibility of multiple code base checkouts -- perhaps the
current stable one and a newer development one.  i'm a big fan of lots
and lots of automated testing so i would write numerous scripts that
would, from the command line, test the code base.

  i want those test scripts to work equally well on the production
checkout and the development checkout, and i also don't want to be
forced to locate those test scripts in any particular directory.  i
might want a totally separate checkout for test scripts, and the
freedom to check them out wherever i want.

  quite simply, i want to be able to check out my test scripts, and
tell them *which* code base to run against.  and i see no way around
that other than to have to explicitly identify the location of the
code base to be tested, and that's what the PROJ_DIR variable was for.
using that single variable, i could reset and point at whatever
checkout i wanted to test.  and i didn't see any easier way to do it.

  i've seen lots of suggestions of very clever ways to have the
components of a single checkout know there the rest of the checkout
is, and most of them would work fine.  but it seems clear that none of
those techniques would give me the ability to do what i want above --
to arbitrarily refer to checkouts from *elsewhere* and have everything
still work.  and there's one more thing.

  to speed up coding, i've added a "utils" directory to the code base,
containing (you guessed it) handy-dandy little utilities.  and since
they're part of the repository, it's not hard for other parts of the
checkout to include them.  but, eventually, someone is going to start
a second, sort-of-related project, and will want to reuse some of
those utilities, and the obvious solution will be to move those
utilities out of the first project and give them their own checkout
(svn external?), and again, i don't want to lock any scripts into any
particular location.

  the single environment variable idea still seems like the obvious
solution, or maybe even more than one.  because i don't see that
there's any way to make this *completely* automated.  at some point,
if i want as much flexibility as possible, a developer who checks out
one or more of these projects has to identify what directories he
wants to work with, and all subsequent includes will work off of that.

  thoughts?  sorry for rambling on so long.

rday
--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

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

--- End Message ---

Reply via email to