[PHP] PHP to server prompt

2010-03-29 Thread Manolis Vlachakis
Hallo there everyone,
i am using a command on the server (kinit)and after that a password is
required to type in
the thing is that i would like that to be done automaticaly from the php
code!
i found that one
http://stackoverflow.com/questions/1...-prompt-in-php

but is not what i want(and is not working)

i thought something like
*
*


   1. fwrite and then the$_SERVER['password here']


and then use the Post method to be writen on the prompt but i am not quite
sure whta to do ..

-- 
Manolis Vlachakis

Nelly's Family Hotel
Visit:   www.nellys-hotel.gr
  www.nellys.gr
Skype : manolis.vlachakis


Re: [PHP] Converting funky characters

2010-03-29 Thread Ashley Sheridan
On Mon, 2010-03-29 at 07:24 +0530, Nilesh Govindarajan wrote:

> On 03/29/2010 07:22 AM, solo hsi wrote:
> > i think you just need function urldecode()
> >
> > On Mon, Mar 29, 2010 at 8:05 AM, Skip Evans  wrote:
> >> Hey all,
> >>
> >> What's the best way to filter/convert characters that don't
> >> translate properly from say news stories to HTML?
> >>
> >> For example, I have a form that people cut and paste the lead
> >> in paragraph from news stories they want to link to from their
> >> sites to the original. And of course things like long dashes,
> >> double quotes, single quotes, etc, always translate is wacky
> >> unprintables when they are rendered, and the user needs to
> >> edit them to replace them with standard characters.
> >>
> >> Is there way to filter this text through a function that will
> >> convert them to web friendly chars?
> >>
> >> Thanks,
> >> Skip
> >>
> >> --
> >> 
> >> Skip Evans
> >> PenguinSites.com, LLC
> >> 503 S Baldwin St, #1
> >> Madison WI 53703
> >> 608.250.2720
> >> http://penguinsites.com
> >> 
> >> Those of you who believe in
> >> telekinesis, raise my hand.
> >>   -- Kurt Vonnegut
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >
> >
> >
> 
> No, only urlencode() won't do the job. He's saying more about the long 
> spaces and quotes, etc.
> 
> -- 
> Nilesh Govindarajan
> Site & Server Administrator
> www.itech7.com
> मेरा भारत महान !
> मम भारत: महत्तम भवतु !
> 


I wrote something that converts these characters, which you'll most
often find when copying text from MS Office:

http://www.ashleysheridan.co.uk/coding_php_remove_ms_crap.php

The second argument to the function just tells it to remove all the
hidden meta tags that MS Office chucks into text that you copy into a
rich text box in a web page, as this can really mess up how the content
is displayed in a web browser.

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




Re: [PHP] PHP to server prompt

2010-03-29 Thread Ashley Sheridan
On Mon, 2010-03-29 at 10:38 +0300, Manolis Vlachakis wrote:

> Hallo there everyone,
> i am using a command on the server (kinit)and after that a password is
> required to type in
> the thing is that i would like that to be done automaticaly from the php
> code!
> i found that one
> http://stackoverflow.com/questions/1...-prompt-in-php
> 
> but is not what i want(and is not working)
> 
> i thought something like
> *
> *
> 
> 
>1. fwrite and then the$_SERVER['password here']
> 
> 
> and then use the Post method to be writen on the prompt but i am not quite
> sure whta to do ..
> 

Most command line functions expect the password to be typed in over
stdin, which you can include in the call to the command line using a
pipe:

exec("echo 'password' | /usr/sbin/function function_args");

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




Re: [PHP] PHP to server prompt

2010-03-29 Thread Manolis Vlachakis
Thanks a lot for your reply,
by mentioning
/usr/sbin/function function_args

you mean the file that runs and requires the password?
from what i had in mind i tried to use the args and argv attributes i used
in linux
but i couldn't make it !

Thanks again




On 29 March 2010 10:58, Ashley Sheridan  wrote:

>  On Mon, 2010-03-29 at 10:38 +0300, Manolis Vlachakis wrote:
>
>
> Hallo there everyone,
> i am using a command on the server (kinit)and after that a password is
> required to type in
> the thing is that i would like that to be done automaticaly from the php
> code!
> i found that one
> http://stackoverflow.com/questions/1...-prompt-in-php
>
> but is not what i want(and is not working)
>
> i thought something like
> *
> *
>
>
>1. fwrite and then the$_SERVER['password here']
>
>
> and then use the Post method to be writen on the prompt but i am not quite
> sure whta to do ..
>
>
>  Most command line functions expect the password to be typed in over stdin,
> which you can include in the call to the command line using a pipe:
>
> exec("echo 'password' | /usr/sbin/function function_args");
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


-- 
Manolis Vlachakis

Nelly's Family Hotel
Visit:   www.nellys-hotel.gr
  www.nellys.gr
Skype : manolis.vlachakis


Re: [PHP]Zip and text files generated are corrupted

2010-03-29 Thread Bastien Helders
>I'm not sure. What is the exact command you are using?

I'll show the code for the two scenario, maybe it'll help. I've edited out
the sensitive information though, but I kept the essence of how it works.

1) Copy the previous file and make modification on it

&1';
exec($command, $output, $status);
//show output and status
}
//I go down again, as it is no more needed when deleting entry in a zip file
chdir('../..');

//Foreach folder to be removed, remove it
foreach($folders_removed as $folder){
$command = 'zip -d ' . $zipname . ' software/hfFolders/'.$folder.'\*
2>&1';
exec($command, $output, $status);
//show output and status
}



2)After all the needed files are gathered in a temporary folder, compress
the all

&1';
//This is the command that timeout in this case
exec($command, $output, $status);
//show output and status

//Do the rest of the operations

>I wonder if the zipArchive route would be easier.

That what I was using before, but it modifies the timestamp of the file that
are already in the zip archive and I can't have that.

>According to the documentation, both Apache and IIS have similar
>timeout values ...
>
>"Your web server can have other timeout configurations that may also
>interrupt PHP execution. Apache has a Timeout directive and IIS has a
>CGI timeout function. Both default to 300 seconds. See your web server
>documentation for specific details."
>(
http://docs.php.net/manual/en/info.configuration.php#ini.max-execution-time)

Yeah I found this config in the httpd-default.conf file of my apache
installation, but as I determined using two consecutive call of microtime()
that the interrupted instructions doesn't go farther as 200 seconds, I don't
see it relevant... (and again after the instruction is interrupted, the
script continue to run.)

>Can you run the command from the shell directly without any problems.
>And run it repeatedly.

I take that the equivalent of the php copy() function is the Windows copy
command line.
In this case, both copy on the big archive and zip -r on a big gathering of
folder are running in the shell without any problem and repeatedly.

2010/3/26 Richard Quadling 

> On 26 March 2010 15:20, Bastien Helders  wrote:
> >  I have checked the rights on the file for the first scenario and no user
> as
> > locked it, I can see it, read it and write into it. I could even delete
> it
> > if I wanted.
> >
> > For the second scenario, it doesn't even apply, as the exec('zip') that
> > timeout try to create a new file (naturally in a folder where the web app
> > user has all the necessary rights)
> >
> > In both case, it is no PHP timeout, as after the copy() in the first
> > scenario, and the exec('zip') in the second scenario, the script continue
> to
> > execute the other instructions, although the manipulation of the big
> files
> > fails.
> >
> > But if it is not a PHP timeout, what is it?
> >
> > 2010/3/26 Richard Quadling 
> >>
> >> On 26 March 2010 12:21, Bastien Helders  wrote:
> >> > I already used error_reporting and set_time_limit and the use of
> >> > ini_set('display_errors', 1); didn't display more exceptions.
> >> >
> >> > However the modification in the exec helped display STDERR I think.
> >> >
> >> > 1) In the first scenario we have the following:
> >> >
> >> > 
> >> > zip warning: ../../build/Patch-6-3-2_Q3P15.zip not found or empty
> >> >
> >> > zip error: Internal logic error (write error on zip file)
> >> > 
> >> >
> >> > The funny thing is, that now it is throwing status 5: "a severe error
> in
> >> > the
> >> > zipfile format was
> >> > detected. Processing probably failed imme­diately." Why It throw a
> >> > status 5
> >> > instead of a status 14, I can't say.
> >> >
> >> > So that's using 'zip -gr', when I stop using the option g and then
> call
> >> > exec('zip -r ...'), then I only get:
> >> >
> >> > 
> >> > zip error: Internal logic error (write error on zip file)
> >> > 
> >> >
> >> > 2) The error messages of the second scenario doesn't surprise me much:
> >> >
> >> > 
> >> > zip error: Unexpected end of zip file (build/Patch-6-3-2_Q3P15.zip)
> >> > 
> >> >
> >> > Which was already known, as the call of copy() on the old patch P14
> crop
> >> > it
> >> > and thus prevent any operation to be done on it.
> >>
> >> So, the error is in the execution of the exec.
> >>
> >> Can you run the exec twice but to 2 different zip files.
> >>
> >> If the issue is that PHP is timing out, then the first error COULD be
> >> due to the process being killed and if so, the second one won't start.
> >>
> >> But if the second one starts, then that pretty much rules out PHP
> >> timeouts.
> >>
> >> I assume you've checked disk space and read access to the files in
> >> question? i.e. they aren't locked by another user?
> >>
> >>
> >> --
> >> -
> >> Richard Quadling
> >> "Standing on the shoulders of some very clever giants!"
> >> EE : http://www.experts-exchange.com/M_248814.html
> >> EE4Free : http://www.experts-exc

Re: [PHP] PHP to server prompt

2010-03-29 Thread Ashley Sheridan
On Mon, 2010-03-29 at 11:13 +0300, Manolis Vlachakis wrote:

> Thanks a lot for your reply,
> by mentioning
> /usr/sbin/function function_args
> 
> you mean the file that runs and requires the password?
> from what i had in mind i tried to use the args and argv attributes i used
> in linux
> but i couldn't make it !
> 
> Thanks again
> 
> 
> 
> 
> On 29 March 2010 10:58, Ashley Sheridan  wrote:
> 
> >  On Mon, 2010-03-29 at 10:38 +0300, Manolis Vlachakis wrote:
> >
> >
> > Hallo there everyone,
> > i am using a command on the server (kinit)and after that a password is
> > required to type in
> > the thing is that i would like that to be done automaticaly from the php
> > code!
> > i found that one
> > http://stackoverflow.com/questions/1...-prompt-in-php
> >
> > but is not what i want(and is not working)
> >
> > i thought something like
> > *
> > *
> >
> >
> >1. fwrite and then the$_SERVER['password here']
> >
> >
> > and then use the Post method to be writen on the prompt but i am not quite
> > sure whta to do ..
> >
> >
> >  Most command line functions expect the password to be typed in over stdin,
> > which you can include in the call to the command line using a pipe:
> >
> > exec("echo 'password' | /usr/sbin/function function_args");
> >
> >   Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> 
> 


Yeah, function would just be the util you're running with exec, which
I've found it's always better to give the absolute path to. I think you
can still pipe stuff across your way.

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




Re: [PHP] Re: optimizing PHP for microseconds

2010-03-29 Thread Bastien Helders
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 

> 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 wrong).
>
> > I would counter and say that if you are NOT optimizing every little drop
> of
> > performance from your scripts, then you're either not running a site
> > sufficiently large enough to matter, or you're doing your customers a
> > disservice.
>
> Or you have no grasp of the tech stack available and certainly aren't
> utilizing it properly; I'm not suggesting that knowing how to use your
> language of choice well is a bad thing, it's great; knock yourself out.
> However, suggesting that optimising a php script for microseconds will
> boost performance in large sites (nay, any site) shows such a loss of
> focus that it's hard to comprehend.
>
> By also considering other posts from yourself (in reply to this and
> other threads) I can firmly say the above is true of you.
>
> Opt

Re: [PHP] PHP to server prompt

2010-03-29 Thread Manolis Vlachakis
did it but it seems that is not working..
do you think because it requires the 'enter' to be given after the password
is required...




On 29 March 2010 11:21, Ashley Sheridan  wrote:

>  On Mon, 2010-03-29 at 11:13 +0300, Manolis Vlachakis wrote:
>
> Thanks a lot for your reply,
> by mentioning
> /usr/sbin/function function_args
>
> you mean the file that runs and requires the password?
> from what i had in mind i tried to use the args and argv attributes i used
> in linux
> but i couldn't make it !
>
> Thanks again
>
>
>
>
> On 29 March 2010 10:58, Ashley Sheridan  wrote:
>
> >  On Mon, 2010-03-29 at 10:38 +0300, Manolis Vlachakis wrote:
> >
> >
> > Hallo there everyone,
> > i am using a command on the server (kinit)and after that a password is
> > required to type in
> > the thing is that i would like that to be done automaticaly from the php
> > code!
> > i found that one
> > http://stackoverflow.com/questions/1...-prompt-in-php
> >
> > but is not what i want(and is not working)
> >
> > i thought something like
> > *
> > *
> >
> >
> >1. fwrite and then the$_SERVER['password here']
> >
> >
> > and then use the Post method to be writen on the prompt but i am not quite
> > sure whta to do ..
> >
> >
> >  Most command line functions expect the password to be typed in over stdin,
> > which you can include in the call to the command line using a pipe:
> >
> > exec("echo 'password' | /usr/sbin/function function_args");
> >
> >   Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
>
>
>
>
> Yeah, function would just be the util you're running with exec, which I've
> found it's always better to give the absolute path to. I think you can still
> pipe stuff across your way.
>
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


-- 
Manolis Vlachakis

Nelly's Family Hotel
Visit:   www.nellys-hotel.gr
  www.nellys.gr
Skype : manolis.vlachakis


Re: [PHP] PHP to server prompt

2010-03-29 Thread Ashley Sheridan
On Mon, 2010-03-29 at 11:36 +0300, Manolis Vlachakis wrote:

> did it but it seems that is not working..
> do you think because it requires the 'enter' to be given after the password
> is required...
> 
> 
> 
> 
> On 29 March 2010 11:21, Ashley Sheridan  wrote:
> 
> >  On Mon, 2010-03-29 at 11:13 +0300, Manolis Vlachakis wrote:
> >
> > Thanks a lot for your reply,
> > by mentioning
> > /usr/sbin/function function_args
> >
> > you mean the file that runs and requires the password?
> > from what i had in mind i tried to use the args and argv attributes i used
> > in linux
> > but i couldn't make it !
> >
> > Thanks again
> >
> >
> >
> >
> > On 29 March 2010 10:58, Ashley Sheridan  wrote:
> >
> > >  On Mon, 2010-03-29 at 10:38 +0300, Manolis Vlachakis wrote:
> > >
> > >
> > > Hallo there everyone,
> > > i am using a command on the server (kinit)and after that a password is
> > > required to type in
> > > the thing is that i would like that to be done automaticaly from the php
> > > code!
> > > i found that one
> > > http://stackoverflow.com/questions/1...-prompt-in-php
> > >
> > > but is not what i want(and is not working)
> > >
> > > i thought something like
> > > *
> > > *
> > >
> > >
> > >1. fwrite and then the$_SERVER['password here']
> > >
> > >
> > > and then use the Post method to be writen on the prompt but i am not quite
> > > sure whta to do ..
> > >
> > >
> > >  Most command line functions expect the password to be typed in over 
> > > stdin,
> > > which you can include in the call to the command line using a pipe:
> > >
> > > exec("echo 'password' | /usr/sbin/function function_args");
> > >
> > >   Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
> >
> >
> >
> >
> > Yeah, function would just be the util you're running with exec, which I've
> > found it's always better to give the absolute path to. I think you can still
> > pipe stuff across your way.
> >
> >
> >   Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> 
> 


No, it doesn't require an enter character to be sent. What code exactly
are you using?

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




Re: [PHP] Re: optimizing PHP for microseconds

2010-03-29 Thread Per Jessen
Bastien Helders 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?

Not enough data.  However, given that it will undoubtedly take seconds
to assemble one such bundle, microseconds are probably not important. 
Depends on how many of those bundles you expect to be able to produce
per minute/hour/day as well as what is supposed to happen with them
after they've been assembled. 



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


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

Re: [PHP] Converting funky characters

2010-03-29 Thread Nilesh Govindarajan

On 03/29/2010 01:22 PM, Ashley Sheridan wrote:

On Mon, 2010-03-29 at 07:24 +0530, Nilesh Govindarajan wrote:

On 03/29/2010 07:22 AM, solo hsi wrote:
>  i think you just need function urldecode()
>
>  On Mon, Mar 29, 2010 at 8:05 AM, Skip Evansmailto:s...@bigskypenguin.com>>   wrote:
>>  Hey all,
>>
>>  What's the best way to filter/convert characters that don't
>>  translate properly from say news stories to HTML?
>>
>>  For example, I have a form that people cut and paste the lead
>>  in paragraph from news stories they want to link to from their
>>  sites to the original. And of course things like long dashes,
>>  double quotes, single quotes, etc, always translate is wacky
>>  unprintables when they are rendered, and the user needs to
>>  edit them to replace them with standard characters.
>>
>>  Is there way to filter this text through a function that will
>>  convert them to web friendly chars?
>>
>>  Thanks,
>>  Skip
>>
>>  --
>>  
>>  Skip Evans
>>  PenguinSites.com, LLC
>>  503 S Baldwin St, #1
>>  Madison WI 53703
>>  608.250.2720
>>  http://penguinsites.com
>>  
>>  Those of you who believe in
>>  telekinesis, raise my hand.
>>-- Kurt Vonnegut
>>
>>  --
>>  PHP General Mailing List (http://www.php.net/)
>>  To unsubscribe, visit:http://www.php.net/unsub.php
>>
>>
>
>
>

No, only urlencode() won't do the job. He's saying more about the long
spaces and quotes, etc.

--
Nilesh Govindarajan
Site&  Server Administrator
www.itech7.com  
मेरा  भारत  महान  !
मम  भारत:महत्तम  भवतु  !



I wrote something that converts these characters, which you'll most
often find when copying text from MS Office:

http://www.ashleysheridan.co.uk/coding_php_remove_ms_crap.php

The second argument to the function just tells it to remove all the
hidden meta tags that MS Office chucks into text that you copy into a
rich text box in a web page, as this can really mess up how the content
is displayed in a web browser.

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




Nice one. But not of use to me. I use geshi on my site, so cannot use 
WYSIWYG editors. Instead I've BBCode and WikiCreole (PEAR Wiki) input 
formats.


--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

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



Re: [PHP] Converting funky characters

2010-03-29 Thread Ashley Sheridan
On Mon, 2010-03-29 at 14:25 +0530, Nilesh Govindarajan wrote:

> On 03/29/2010 01:22 PM, Ashley Sheridan wrote:
> > On Mon, 2010-03-29 at 07:24 +0530, Nilesh Govindarajan wrote:
> >> On 03/29/2010 07:22 AM, solo hsi wrote:
> >> >  i think you just need function urldecode()
> >> >
> >> >  On Mon, Mar 29, 2010 at 8:05 AM, Skip Evans >> > >   wrote:
> >> >>  Hey all,
> >> >>
> >> >>  What's the best way to filter/convert characters that don't
> >> >>  translate properly from say news stories to HTML?
> >> >>
> >> >>  For example, I have a form that people cut and paste the lead
> >> >>  in paragraph from news stories they want to link to from their
> >> >>  sites to the original. And of course things like long dashes,
> >> >>  double quotes, single quotes, etc, always translate is wacky
> >> >>  unprintables when they are rendered, and the user needs to
> >> >>  edit them to replace them with standard characters.
> >> >>
> >> >>  Is there way to filter this text through a function that will
> >> >>  convert them to web friendly chars?
> >> >>
> >> >>  Thanks,
> >> >>  Skip
> >> >>
> >> >>  --
> >> >>  
> >> >>  Skip Evans
> >> >>  PenguinSites.com, LLC
> >> >>  503 S Baldwin St, #1
> >> >>  Madison WI 53703
> >> >>  608.250.2720
> >> >>  http://penguinsites.com
> >> >>  
> >> >>  Those of you who believe in
> >> >>  telekinesis, raise my hand.
> >> >>-- Kurt Vonnegut
> >> >>
> >> >>  --
> >> >>  PHP General Mailing List (http://www.php.net/)
> >> >>  To unsubscribe, visit:http://www.php.net/unsub.php
> >> >>
> >> >>
> >> >
> >> >
> >> >
> >>
> >> No, only urlencode() won't do the job. He's saying more about the long
> >> spaces and quotes, etc.
> >>
> >> --
> >> Nilesh Govindarajan
> >> Site&  Server Administrator
> >> www.itech7.com  
> >> मेरा  भारत  महान  !
> >> मम  भारत:महत्तम  भवतु  !
> >>
> >
> > I wrote something that converts these characters, which you'll most
> > often find when copying text from MS Office:
> >
> > http://www.ashleysheridan.co.uk/coding_php_remove_ms_crap.php
> >
> > The second argument to the function just tells it to remove all the
> > hidden meta tags that MS Office chucks into text that you copy into a
> > rich text box in a web page, as this can really mess up how the content
> > is displayed in a web browser.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> 
> Nice one. But not of use to me. I use geshi on my site, so cannot use 
> WYSIWYG editors. Instead I've BBCode and WikiCreole (PEAR Wiki) input 
> formats.
> 
> -- 
> Nilesh Govindarajan
> Site & Server Administrator
> www.itech7.com
> मेरा भारत महान !
> मम भारत: महत्तम भवतु !
> 


It's not just for wysiwyg editors, that's just the second part of the
function. The first does just what you asked for.

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




Re: [PHP] Converting funky characters

2010-03-29 Thread Nilesh Govindarajan

On 03/29/2010 02:21 PM, Ashley Sheridan wrote:

On Mon, 2010-03-29 at 14:25 +0530, Nilesh Govindarajan wrote:

On 03/29/2010 01:22 PM, Ashley Sheridan wrote:
>  On Mon, 2010-03-29 at 07:24 +0530, Nilesh Govindarajan wrote:
>>  On 03/29/2010 07:22 AM, solo hsi wrote:
>>  >   i think you just need function urldecode()
>>  >
>>  >   On Mon, Mar 29, 2010 at 8:05 AM, Skip Evansmailto:s...@bigskypenguin.com>   >wrote:
>>  >>   Hey all,
>>  >>
>>  >>   What's the best way to filter/convert characters that don't
>>  >>   translate properly from say news stories to HTML?
>>  >>
>>  >>   For example, I have a form that people cut and paste the lead
>>  >>   in paragraph from news stories they want to link to from their
>>  >>   sites to the original. And of course things like long dashes,
>>  >>   double quotes, single quotes, etc, always translate is wacky
>>  >>   unprintables when they are rendered, and the user needs to
>>  >>   edit them to replace them with standard characters.
>>  >>
>>  >>   Is there way to filter this text through a function that will
>>  >>   convert them to web friendly chars?
>>  >>
>>  >>   Thanks,
>>  >>   Skip
>>  >>
>>  >>   --
>>  >>   
>>  >>   Skip Evans
>>  >>   PenguinSites.com, LLC
>>  >>   503 S Baldwin St, #1
>>  >>   Madison WI 53703
>>  >>   608.250.2720
>>  >>   http://penguinsites.com
>>  >>   
>>  >>   Those of you who believe in
>>  >>   telekinesis, raise my hand.
>>  >> -- Kurt Vonnegut
>>  >>
>>  >>   --
>>  >>   PHP General Mailing List (http://www.php.net/)
>>  >>   To unsubscribe, visit:http://www.php.net/unsub.php
>>  >>
>>  >>
>>  >
>>  >
>>  >
>>
>>  No, only urlencode() won't do the job. He's saying more about the long
>>  spaces and quotes, etc.
>>
>>  --
>>  Nilesh Govindarajan
>>  Site&   Server Administrator
>>  www.itech7.com     
>>  मेरा   भारत   महान   !
>>  मम   भारत:महत्तम   भवतु   !
>>
>
>  I wrote something that converts these characters, which you'll most
>  often find when copying text from MS Office:
>
>  http://www.ashleysheridan.co.uk/coding_php_remove_ms_crap.php
>
>  The second argument to the function just tells it to remove all the
>  hidden meta tags that MS Office chucks into text that you copy into a
>  rich text box in a web page, as this can really mess up how the content
>  is displayed in a web browser.
>
>  Thanks,
>  Ash
>  http://www.ashleysheridan.co.uk
>
>

Nice one. But not of use to me. I use geshi on my site, so cannot use
WYSIWYG editors. Instead I've BBCode and WikiCreole (PEAR Wiki) input
formats.

--
Nilesh Govindarajan
Site&  Server Administrator
www.itech7.com  
मेरा  भारत  महान  !
मम  भारत:महत्तम  भवतु  !



It's not just for wysiwyg editors, that's just the second part of the
function. The first does just what you asked for.

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




I didn't ask anything in this topic. It was Skip Evans the thread starter.

--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

--
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 Nathan Rixham
Bastien Helders 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.

Hi Bastien,

A good question, and a good use-case.

Firstly, to clarify (generally speaking), "optimising for microseconds"
is a real thing, but not how it's been conveyed previously. There is a
big difference between knowing your language / target of choice (e.g.
creating fast code); and the real "optimising for microseconds" which is
shaving off every microsecond possible once all other routes of
optimisation have been taken (and where it is needed).

There is always a case for creating code that executes quickly, that is
a big part of our job - but worrying about microseconds and completely
disregarding forms of optimisation in the full tech stack that shave of
hours of runtime per day isn't the best course of action :)

On to your specific use-case. It's all relative and without all the
details I can't really give an accurate opinion!

PHP can easily be leveraged to use the file system in order to create
the bundle too, move files over to a temp directory; tar/gzip everything
up and then redirect the user to (or store) the location of said file.
Taking an approach like this will considerably lower the amount of
resources consumed by php / web server and thus keep the system speedy
for all (and is more than likely quicker). And obviously all future hits
to said bundle won't need to touch php.

If you don't want to keep the user waiting then you could save the
instructions needed and have a cron job or daemon pick up on them and
then notify the user(s) when the file has been created.

Many, many approaches - generally speaking this is the best advice I can
give:

1: always look for the tech that has been designed to do the job you
need, and then use it - if possible.

2: test, time & measure. Try different ways of dealing with the
"heaviest" bit, get the numbers and take a note of what processes it
impacts - then compare.

For example if 3 users run the script at the same time with PHP doing
the heavy lifting, will it max out the processor or push the web server
in to using swap memory? If something fails (a known / handled
exception) then does the process take a double hit and need run a second
time?

You are your own best friend with this one, take time out, negate php
for a moment and just think of the fastest way to do what you need (all
things considered) then go try it out - PHP can still be the controller
for any factored out processes :)

Do hope that helps,

Nathan

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



[PHP] Sessions and Security Concerns

2010-03-29 Thread Ben Stones
Hi,

I'm just wondering whether there are any apparent security concerns I should
be aware of when using sessions in my PHP scripts. I understand that
sessions are tracked with an individual user via a session ID which is
stored in a temporary location on the server, as well as a PHPSESSID cookie
assigned to the end user's client, but the server my website is hosted on
(and which I'll be developing my PHP script on) doesn't allow you to create
a session ID via the URL (i.e. index.php?PHPSESSID=1234) so I *presume* only
the server can generate a session ID for the end user when I call the
session_start function? So do I still need to call session_regenerate_id for
security purposes when an end user has entered the correct login credentials
- would this be necessary since you cant set a session ID via the URL?

Thanks,
Ben.


Re: [PHP] bug tracking system

2010-03-29 Thread Anshul Agrawal
There is something new based on Trac but written in PHP.

mtrack (http://bitbucket.org/wez/mtrack/wiki/Home)

It is written by one of the PHP Core Developers (Wez Furlong). May be you
want to try it out.

Best,
Anshul


On Sun, Mar 28, 2010 at 10:36 PM, Nathan Rixham  wrote:

> shiplu wrote:
> > I want to add with Andre.
> > I am looking for a free hosted bug tracking solution. I can not afford
> > to host it in my web server.
> > So is there any free one??
> > It should not be public. Only me and my clients will be able to see it.
> >
> > Thanks
> >
>
> yes, for all cases, commercial or not; self hosted or remote; indefero
> [1] is a fantastic quick to use solution:
>
> [1] http://www.indefero.net/
>
> Many Regards,
>
> Nathan
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Sessions and Security Concerns

2010-03-29 Thread Ashley Sheridan
On Mon, 2010-03-29 at 12:24 +0100, Ben Stones wrote:

> Hi,
> 
> I'm just wondering whether there are any apparent security concerns I should
> be aware of when using sessions in my PHP scripts. I understand that
> sessions are tracked with an individual user via a session ID which is
> stored in a temporary location on the server, as well as a PHPSESSID cookie
> assigned to the end user's client, but the server my website is hosted on
> (and which I'll be developing my PHP script on) doesn't allow you to create
> a session ID via the URL (i.e. index.php?PHPSESSID=1234) so I *presume* only
> the server can generate a session ID for the end user when I call the
> session_start function? So do I still need to call session_regenerate_id for
> security purposes when an end user has entered the correct login credentials
> - would this be necessary since you cant set a session ID via the URL?
> 
> Thanks,
> Ben.


Just setting a URL variable won't actually create a session, you have to
use the PHP session functions to create one.

Using session_regenerate_id() won't do that much for security. If you
are really worried, then consider a security certificate. Even a
self-issued one is better than nothing, and you can generate these for
free.

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




Re: [PHP] Sessions and Security Concerns

2010-03-29 Thread Nathan Rixham
Ashley Sheridan wrote:
> On Mon, 2010-03-29 at 12:24 +0100, Ben Stones wrote:
> 
>> Hi,
>>
>> I'm just wondering whether there are any apparent security concerns I should
>> be aware of when using sessions in my PHP scripts. I understand that
>> sessions are tracked with an individual user via a session ID which is
>> stored in a temporary location on the server, as well as a PHPSESSID cookie
>> assigned to the end user's client, but the server my website is hosted on
>> (and which I'll be developing my PHP script on) doesn't allow you to create
>> a session ID via the URL (i.e. index.php?PHPSESSID=1234) so I *presume* only
>> the server can generate a session ID for the end user when I call the
>> session_start function? So do I still need to call session_regenerate_id for
>> security purposes when an end user has entered the correct login credentials
>> - would this be necessary since you cant set a session ID via the URL?
>>
>> Thanks,
>> Ben.
> 
> 
> Just setting a URL variable won't actually create a session, you have to
> use the PHP session functions to create one.
> 
> Using session_regenerate_id() won't do that much for security. If you
> are really worried, then consider a security certificate. Even a
> self-issued one is better than nothing, and you can generate these for
> free.

worth noting that you can also issue client side ssl certificates to
your users; 100% secure, self-signed thus free, either by creating a
pki12 w/ php or by using the html KEYGEN element - the ssl cert installs
directly in the users browser. You can use the subjectAltName attribute
of the certificate to save a users unique id.

And thus, 0 click login, perfectly secure auth all done through https -
further meaning you can completely negate sessions/cookies and all the
related insecurities.

further still, you can boot this up to foaf+ssl giving users one unique
web id for themselves, and in full control of there own profile / login
etc; (like openid done right and one steriods)

Will be the defacto industry standard in a couple of years, so may as
well adopt early.

Regards!

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



Re: [PHP] bug tracking system

2010-03-29 Thread Jan G.B.
2010/3/29 Anshul Agrawal 

> There is something new based on Trac but written in PHP.
>
> mtrack (http://bitbucket.org/wez/mtrack/wiki/Home)
>
> It is written by one of the PHP Core Developers (Wez Furlong). May be you
> want to try it out.
>
> And there's something quite new that's aimed to be like trac : JotBug
http://code.google.com/p/jotbug/


Regards


Re: [PHP] how to provide download of files mow in documentroot

2010-03-29 Thread Jan G.B.
Top posting sucks, so I'll answer the post somewhere down there.


2010/3/29 Devendra Jadhav 

> Then you can do file_get_contents within PHP. or any file handling
> mechanism.
> >> On Mon, Mar 29, 2010 at 1:00 AM, ebhakt  wrote:
> >>> Hi
> >>> i am writing a web application in php
> >>> this webapp primarily focuses on file uploads and downloads
> >>> the uploaded files will be saved in a folder which is not in document
> >>> root
> >>> and my query is how will i be able to provide download to such files
> not
> >>> located in document root via php
> >>>
>

Try something like that


Depending on the $filesize, you should use something else than
file_get_contents() (for example fopen/fread). file_get_contents on a huge
file will exhaust your webservers RAM.

Regards


Re: [PHP] is there any setting to declare the member variables in constructor?

2010-03-29 Thread Richard Quadling
On 27 March 2010 17:50, solo hsi  wrote:
> now i'm re-writing some script to output pdf files. the original code
> is based on fpdf, but as you know, fpdf can't deal with the characters
> in utf8.

>From http://www.fpdf.org/?lang=en

"What languages can I use?

The class can produce documents in many languages other than the
Western European ones: Central European, Cyrillic, Greek, Baltic and
Thai, provided you own TrueType or Type1 fonts with the desired
character set. Chinese, Japanese and Korean are supported too."

So, if you have the font for it, you should be able to encode the data
easily enough. No matter what encoding you are using, unless the font
you want to use has a glyph for it, you can't use it. This is more
often the problem I've found.

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

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



[PHP] Re: Converting funky characters

2010-03-29 Thread Al



On 3/28/2010 8:05 PM, Skip Evans wrote:

Hey all,

What's the best way to filter/convert characters that don't
translate properly from say news stories to HTML?

For example, I have a form that people cut and paste the lead
in paragraph from news stories they want to link to from their
sites to the original. And of course things like long dashes,
double quotes, single quotes, etc, always translate is wacky
unprintables when they are rendered, and the user needs to
edit them to replace them with standard characters.

Is there way to filter this text through a function that will
convert them to web friendly chars?

Thanks,
Skip



Here's how I handle the problem:

//region* Translate table for dumb Windows chars when user pastes from Word; 
function strips all >160


$win1252ToPlainTextArray = array(
chr(130) => ',',
chr(131) => '',
chr(132) => ',,',
chr(133) => '...',
chr(134) => '+',
chr(135) => '',
chr(139) => '<',
chr(145) => '\'',
chr(146) => '\'',
chr(147) => '"',
chr(148) => '"',
chr(149) => '*',
chr(150) => '-',
chr(151) => '-',
chr(155) => '>',
chr(160) => ' ',
);
//endregion

function cleanWin1252Text($str, $win1252ToPlainTextArray)
{
  $str = strtr($str, $win1252ToPlainTextArray);
  $str = trim($str);
  $patterns = array('%[\x7F-\x81]%', '%[\x83]%', '%[\x87-\x8A]%', 
'%[\x8C-\x90]%', '%[\x98-\xff]%');


  return preg_replace($patterns, '', $str); //Strip
}




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



Re: [PHP] how to provide download of files mow in documentroot

2010-03-29 Thread Nathan Rixham
Jan G.B. wrote:
> Top posting sucks, so I'll answer the post somewhere down there.
> 
> 
> 2010/3/29 Devendra Jadhav 
> 
>> Then you can do file_get_contents within PHP. or any file handling
>> mechanism.
 On Mon, Mar 29, 2010 at 1:00 AM, ebhakt  wrote:
> Hi
> i am writing a web application in php
> this webapp primarily focuses on file uploads and downloads
> the uploaded files will be saved in a folder which is not in document
> root
> and my query is how will i be able to provide download to such files
>> not
> located in document root via php
>
> 
> Try something like that
>  $content = file_get_contents($filename);
> $etag = md5($content);
> header('Last-Modified: '.gmdate('D, d M Y H:i:s',
> filemtime($filename)).' GMT');
> header('ETag: '.$etag);
> header('Accept-Ranges: bytes');
> header('Content-Length: '.strlen($content));
> header('Cache-Control: '.$cache_value); // you decide
> header('Content-type: '.$should_be_set);
> echo $content;
> exit;
> ?>
> 
> Depending on the $filesize, you should use something else than
> file_get_contents() (for example fopen/fread). file_get_contents on a huge
> file will exhaust your webservers RAM.

Yup, so you can map the  in web server config; then
"allow from" only from localhost + yourdomain. This means you can then
request it like an url and do a head request to get the etag etc then
return a 304 not modified if you received a matching etag Last-Modified
etc; (thus meaning you only file_get_contents when really really needed).

I'd advise against saying you Accept-Ranges bytes if you don't accept
byte ranges (ie you aren't going to send little bits of the file).

If you need the downloads to be secure only; then you could easily
negate php all together and simply expose the directory via a location
so that it is web accessible and set it up to ask for "auth" using
htpasswd; a custom script, ldap or whatever.

And if you don't need security then why have php involved at all? simply
symlink to the directory or expose it via http and be done with the
problem in a minute or two.

Regards!

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



Re: [PHP] bug tracking system

2010-03-29 Thread Anshul Agrawal
On Mon, Mar 29, 2010 at 5:30 PM, Jan G.B.  wrote:

>
> 2010/3/29 Anshul Agrawal 
>
> There is something new based on Trac but written in PHP.
>>
>> mtrack (http://bitbucket.org/wez/mtrack/wiki/Home)
>>
>> It is written by one of the PHP Core Developers (Wez Furlong). May be you
>> want to try it out.
>>
>> And there's something quite new that's aimed to be like trac : JotBug
> http://code.google.com/p/jotbug/
>
>
> Regards
>

I kept wondering for long time why PHP community doesn't have something at
least as cool as Trac. Times are changing :)

-- 
Anshul


Re: [PHP] how to provide download of files mow in documentroot

2010-03-29 Thread Jan G.B.
2010/3/29 Nathan Rixham 

> Jan G.B. wrote:
> > Top posting sucks, so I'll answer the post somewhere down there.
> > 
> >
> > 2010/3/29 Devendra Jadhav 
> >
> >> Then you can do file_get_contents within PHP. or any file handling
> >> mechanism.
>  On Mon, Mar 29, 2010 at 1:00 AM, ebhakt  wrote:
> > Hi
> > i am writing a web application in php
> > this webapp primarily focuses on file uploads and downloads
> > the uploaded files will be saved in a folder which is not in document
> > root
> > and my query is how will i be able to provide download to such files
> >> not
> > located in document root via php
> >
> >
> > Try something like that
> >  > $content = file_get_contents($filename);
> > $etag = md5($content);
> > header('Last-Modified: '.gmdate('D, d M Y H:i:s',
> > filemtime($filename)).' GMT');
> > header('ETag: '.$etag);
> > header('Accept-Ranges: bytes');
> > header('Content-Length: '.strlen($content));
> > header('Cache-Control: '.$cache_value); // you decide
> > header('Content-type: '.$should_be_set);
> > echo $content;
> > exit;
> > ?>
> >
> > Depending on the $filesize, you should use something else than
> > file_get_contents() (for example fopen/fread). file_get_contents on a
> huge
> > file will exhaust your webservers RAM.
>
> Yup, so you can map the  in web server config; then
> "allow from" only from localhost + yourdomain. This means you can then
> request it like an url and do a head request to get the etag etc then
> return a 304 not modified if you received a matching etag Last-Modified
> etc; (thus meaning you only file_get_contents when really really needed).
>
> I'd advise against saying you Accept-Ranges bytes if you don't accept
> byte ranges (ie you aren't going to send little bits of the file).
>
> If you need the downloads to be secure only; then you could easily
> negate php all together and simply expose the directory via a location
> so that it is web accessible and set it up to ask for "auth" using
> htpasswd; a custom script, ldap or whatever.
>
> And if you don't need security then why have php involved at all? simply
> symlink to the directory or expose it via http and be done with the
> problem in a minute or two.
>
> Regards!
>

In my opinion, serving user-content on a productive server is wicked sick.
You don't want your visitors to upload malicous files that may trigger some
modules as mod_php in apache. So it makes sense to store user-uploads
outside of a docroot and with no symlink or whatsover.

One more thing added: your RAM will be exhausted even if you open that 600mb
file just once.
Apaches memory handling is a bit weird: if *one* apache process is using
200mb RAM on *one* impression because your application uses that much, then
that process will not release the memory while it's serving another 1000
requests for `clear.gif` which is maybe 850b in size.
So better forget that file_get_contents)( when the filesize can be huge. :-)

Regards


Re: [PHP] how to provide download of files mow in documentroot

2010-03-29 Thread Anshul Agrawal
On Mon, Mar 29, 2010 at 6:10 PM, Nathan Rixham  wrote:

> Jan G.B. wrote:
> > Top posting sucks, so I'll answer the post somewhere down there.
> > 
> >
> > 2010/3/29 Devendra Jadhav 
> >
> >> Then you can do file_get_contents within PHP. or any file handling
> >> mechanism.
>  On Mon, Mar 29, 2010 at 1:00 AM, ebhakt  wrote:
> > Hi
> > i am writing a web application in php
> > this webapp primarily focuses on file uploads and downloads
> > the uploaded files will be saved in a folder which is not in document
> > root
> > and my query is how will i be able to provide download to such files
> >> not
> > located in document root via php
> >
> >
> > Try something like that
> >  > $content = file_get_contents($filename);
> > $etag = md5($content);
> > header('Last-Modified: '.gmdate('D, d M Y H:i:s',
> > filemtime($filename)).' GMT');
> > header('ETag: '.$etag);
> > header('Accept-Ranges: bytes');
> > header('Content-Length: '.strlen($content));
> > header('Cache-Control: '.$cache_value); // you decide
> > header('Content-type: '.$should_be_set);
> > echo $content;
> > exit;
> > ?>
> >
> > Depending on the $filesize, you should use something else than
> > file_get_contents() (for example fopen/fread). file_get_contents on a
> huge
> > file will exhaust your webservers RAM.
>
> Yup, so you can map the  in web server config; then
> "allow from" only from localhost + yourdomain. This means you can then
> request it like an url and do a head request to get the etag etc then
> return a 304 not modified if you received a matching etag Last-Modified
> etc; (thus meaning you only file_get_contents when really really needed).
>
> I'd advise against saying you Accept-Ranges bytes if you don't accept
> byte ranges (ie you aren't going to send little bits of the file).
>
> If you need the downloads to be secure only; then you could easily
> negate php all together and simply expose the directory via a location
> so that it is web accessible and set it up to ask for "auth" using
> htpasswd; a custom script, ldap or whatever.
>
> And if you don't need security then why have php involved at all? simply
> symlink to the directory or expose it via http and be done with the
> problem in a minute or two.
>
> Regards!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Also look at readfile() and fpassthru if dealing with large files.

Moreover, if you have control over the webserver then you can use PHP only
for authenticating the getFile request and offload the file delivery
operation to your webserver (Apache, NginX, lighttpd) using "X-SendFile"
header in the response.

Best,
Anshul


Re: [PHP] is there any setting to declare the member variables in constructor?

2010-03-29 Thread solo hsi
sure, i know fpdf can deal with asian character like Chinese, but it
can't work with utf-8 charactor so that i have to replace it with
tcpdf.

On Mon, Mar 29, 2010 at 8:14 PM, Richard Quadling
 wrote:
> On 27 March 2010 17:50, solo hsi  wrote:
>> now i'm re-writing some script to output pdf files. the original code
>> is based on fpdf, but as you know, fpdf can't deal with the characters
>> in utf8.
>
> From http://www.fpdf.org/?lang=en
>
> "What languages can I use?
>
> The class can produce documents in many languages other than the
> Western European ones: Central European, Cyrillic, Greek, Baltic and
> Thai, provided you own TrueType or Type1 fonts with the desired
> character set. Chinese, Japanese and Korean are supported too."
>
> So, if you have the font for it, you should be able to encode the data
> easily enough. No matter what encoding you are using, unless the font
> you want to use has a glyph for it, you can't use it. This is more
> often the problem I've found.
>
> 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=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>



-- 
solo(xzy...@gmail.com)

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



Re: [PHP] is there any setting to declare the member variables in constructor?

2010-03-29 Thread Richard Quadling
On 29 March 2010 16:47, solo hsi  wrote:
> sure, i know fpdf can deal with asian character like Chinese, but it
> can't work with utf-8 charactor so that i have to replace it with
> tcpdf.
>
> On Mon, Mar 29, 2010 at 8:14 PM, Richard Quadling
>  wrote:
>> On 27 March 2010 17:50, solo hsi  wrote:
>>> now i'm re-writing some script to output pdf files. the original code
>>> is based on fpdf, but as you know, fpdf can't deal with the characters
>>> in utf8.
>>
>> From http://www.fpdf.org/?lang=en
>>
>> "What languages can I use?
>>
>> The class can produce documents in many languages other than the
>> Western European ones: Central European, Cyrillic, Greek, Baltic and
>> Thai, provided you own TrueType or Type1 fonts with the desired
>> character set. Chinese, Japanese and Korean are supported too."
>>
>> So, if you have the font for it, you should be able to encode the data
>> easily enough. No matter what encoding you are using, unless the font
>> you want to use has a glyph for it, you can't use it. This is more
>> often the problem I've found.
>>
>> 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=ZEND002498&r=213474731
>> ZOPA : http://uk.zopa.com/member/RQuadling
>>
>
>
>
> --
> solo(xzy...@gmail.com)
>

Aha! I see what you mean.

http://www.fpdf.org/en/tutorial/tuto7.htm

Uses an encoding and only allows 256 characters.

Hmm.

With regard to your issue, it sounds like the class is extended
further or uses magic functions to set/get missing properties.

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

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



Re: [PHP] is there any setting to declare the member variables in constructor?

2010-03-29 Thread solo hsi
i have done my work, replaced fpdf with tcpdf, just by using fpdi:)

On Tue, Mar 30, 2010 at 12:12 AM, Richard Quadling
 wrote:
> On 29 March 2010 16:47, solo hsi  wrote:
>> sure, i know fpdf can deal with asian character like Chinese, but it
>> can't work with utf-8 charactor so that i have to replace it with
>> tcpdf.
>>
>> On Mon, Mar 29, 2010 at 8:14 PM, Richard Quadling
>>  wrote:
>>> On 27 March 2010 17:50, solo hsi  wrote:
 now i'm re-writing some script to output pdf files. the original code
 is based on fpdf, but as you know, fpdf can't deal with the characters
 in utf8.
>>>
>>> From http://www.fpdf.org/?lang=en
>>>
>>> "What languages can I use?
>>>
>>> The class can produce documents in many languages other than the
>>> Western European ones: Central European, Cyrillic, Greek, Baltic and
>>> Thai, provided you own TrueType or Type1 fonts with the desired
>>> character set. Chinese, Japanese and Korean are supported too."
>>>
>>> So, if you have the font for it, you should be able to encode the data
>>> easily enough. No matter what encoding you are using, unless the font
>>> you want to use has a glyph for it, you can't use it. This is more
>>> often the problem I've found.
>>>
>>> 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=ZEND002498&r=213474731
>>> ZOPA : http://uk.zopa.com/member/RQuadling
>>>
>>
>>
>>
>> --
>> solo(xzy...@gmail.com)
>>
>
> Aha! I see what you mean.
>
> http://www.fpdf.org/en/tutorial/tuto7.htm
>
> Uses an encoding and only allows 256 characters.
>
> Hmm.
>
> With regard to your issue, it sounds like the class is extended
> further or uses magic functions to set/get missing properties.
>
> --
> -
> 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
>



-- 
solo(xzy...@gmail.com)

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



RE: [PHP] Please guide in selection of Framework: according to your experience

2010-03-29 Thread Daevid Vincent
 

> -Original Message-
> From: Vishal Rewari [mailto:rewari.vis...@gmail.com] 
> Sent: Friday, March 26, 2010 9:29 PM
> 
> I am vishal, I have recently started development in PHP
> I have come across these PHP frameworks:
> 
>1. Codeigniter
>2. Symphony
>3. CakePHP
>4. PEAR
> 
> Please guide me which one of them is *good in performance ? available
> functionality ? Easy to use and configure* or the one you 
> would recommend according to your experience.

I was forced to use Symfony before. Hated every second of it. The company
eventually folded, no doubt in part due to the poor decision to use this
framework.

For example, using the "Symfony way" of looping over various news stories,
creating objects and the whole ORM and all that crap, it would take a
second or so per story to process. With thousands of stories this took
hours to process. We then said F-it and re-wrote the parser in straight up
PHP and now the processing took a couple of minutes.

> or should I stick to native call from PHP?

Yes.

Most real developers do NOT use off-the-shelf frameworks. We generally roll
our own since no framework will do everything you're going to want or need
for your particular project, and then your stuck either trying to wedge
something in, or hoping "they" eventually catch up to your needs. They try
to be all things to all people and therefore you carry a lot of baggage and
bloat you don't want/need. And the biggest reason to avoid them is if your
project grows, now you have to find not only a skilled PHP developer, but
one that knows this additional framework and is proficient enough to use it
well. It's just a hassle in the end and puts digital handcuffs on you.
Write some wrappers for your DB calls and other useful routines and KISS.
Frameworks are great for a quick proto-type, but IMHO, why waste energy
when you'll just have to re-write it again for real. Do it right from the
start.

http://www.rapidpoll.net/8opnt1e




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



Re: [PHP] how to provide download of files mow in documentroot

2010-03-29 Thread Nathan Rixham
Jan G.B. wrote:
> 2010/3/29 Nathan Rixham 
> 
>> Jan G.B. wrote:
>>> Top posting sucks, so I'll answer the post somewhere down there.
>>> 
>>>
>>> 2010/3/29 Devendra Jadhav 
>>>
 Then you can do file_get_contents within PHP. or any file handling
 mechanism.
>> On Mon, Mar 29, 2010 at 1:00 AM, ebhakt  wrote:
>>> Hi
>>> i am writing a web application in php
>>> this webapp primarily focuses on file uploads and downloads
>>> the uploaded files will be saved in a folder which is not in document
>>> root
>>> and my query is how will i be able to provide download to such files
 not
>>> located in document root via php
>>>
>>> Try something like that
>>> >> $content = file_get_contents($filename);
>>> $etag = md5($content);
>>> header('Last-Modified: '.gmdate('D, d M Y H:i:s',
>>> filemtime($filename)).' GMT');
>>> header('ETag: '.$etag);
>>> header('Accept-Ranges: bytes');
>>> header('Content-Length: '.strlen($content));
>>> header('Cache-Control: '.$cache_value); // you decide
>>> header('Content-type: '.$should_be_set);
>>> echo $content;
>>> exit;
>>> ?>
>>>
>>> Depending on the $filesize, you should use something else than
>>> file_get_contents() (for example fopen/fread). file_get_contents on a
>> huge
>>> file will exhaust your webservers RAM.
>> Yup, so you can map the  in web server config; then
>> "allow from" only from localhost + yourdomain. This means you can then
>> request it like an url and do a head request to get the etag etc then
>> return a 304 not modified if you received a matching etag Last-Modified
>> etc; (thus meaning you only file_get_contents when really really needed).
>>
>> I'd advise against saying you Accept-Ranges bytes if you don't accept
>> byte ranges (ie you aren't going to send little bits of the file).
>>
>> If you need the downloads to be secure only; then you could easily
>> negate php all together and simply expose the directory via a location
>> so that it is web accessible and set it up to ask for "auth" using
>> htpasswd; a custom script, ldap or whatever.
>>
>> And if you don't need security then why have php involved at all? simply
>> symlink to the directory or expose it via http and be done with the
>> problem in a minute or two.
>>
>> Regards!
>>
> 
> In my opinion, serving user-content on a productive server is wicked sick.
> You don't want your visitors to upload malicous files that may trigger some
> modules as mod_php in apache. So it makes sense to store user-uploads
> outside of a docroot and with no symlink or whatsover.

even the simplest of server configurations will ensure safety. just use
.htaccess to SetHandler default-handler which treats everything as
static content and serves it right up.

> One more thing added: your RAM will be exhausted even if you open that 600mb
> file just once.
> Apaches memory handling is a bit weird: if *one* apache process is using
> 200mb RAM on *one* impression because your application uses that much, then
> that process will not release the memory while it's serving another 1000
> requests for `clear.gif` which is maybe 850b in size.

again everything depends on how you have your server configured; you can
easily tell apache to kill each child after one run or a whole host of
other configs; but ultimately if you can avoid opening up that file in
php then do; serving statically as above is the cleanest quickest way to
do it (other than using s3 or similar).

regards!

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



Re: [PHP] Please guide in selection of Framework: according to your experience

2010-03-29 Thread Nathan Rixham
Daevid Vincent wrote:
>  
> 
>> -Original Message-
>> From: Vishal Rewari [mailto:rewari.vis...@gmail.com] 
>> Sent: Friday, March 26, 2010 9:29 PM
>>
>> I am vishal, I have recently started development in PHP
>> I have come across these PHP frameworks:
>>
>>1. Codeigniter
>>2. Symphony
>>3. CakePHP
>>4. PEAR
>>
>> Please guide me which one of them is *good in performance ? available
>> functionality ? Easy to use and configure* or the one you 
>> would recommend according to your experience.
> 
> I was forced to use Symfony before. Hated every second of it. The company
> eventually folded, no doubt in part due to the poor decision to use this
> framework.
> 
> For example, using the "Symfony way" of looping over various news stories,
> creating objects and the whole ORM and all that crap, it would take a
> second or so per story to process. With thousands of stories this took
> hours to process. We then said F-it and re-wrote the parser in straight up
> PHP and now the processing took a couple of minutes.
> 
>> or should I stick to native call from PHP?
> 
> Yes.
> 
> Most real developers do NOT use off-the-shelf frameworks. We generally roll
> our own since no framework will do everything you're going to want or need
> for your particular project, and then your stuck either trying to wedge
> something in, or hoping "they" eventually catch up to your needs. They try
> to be all things to all people and therefore you carry a lot of baggage and
> bloat you don't want/need. And the biggest reason to avoid them is if your
> project grows, now you have to find not only a skilled PHP developer, but
> one that knows this additional framework and is proficient enough to use it
> well. It's just a hassle in the end and puts digital handcuffs on you.
> Write some wrappers for your DB calls and other useful routines and KISS.
> Frameworks are great for a quick proto-type, but IMHO, why waste energy
> when you'll just have to re-write it again for real. Do it right from the
> start.

Agreed (strangely) I've always opted for roll your own; however one
exception is zend framework, v good and nice and modular; another
exception is standard "do the job well" libraries such as reCaptcha lib,
SimplePie, some PEAR stuff and gubbins like that - often saves time and
the code is pretty solid.

Personally I find a good collection of classes I've built up over the
years fit's the bill perfectly; but then I've had the years to build
them up.

If you've got the choice and the time/budget/inclination/ability it's a
good approach to roll your own from scratch - if you don't or you're
part of a huge team then odds are it'll be picking the lightest
framework you can, which the most dev's know, to get going (java style
"urm should we use spring or ejb").

Often the get it working then optimise is a required approach for sweat
shops (ahem. sorry I mean agencies). Again though, if you are employed
always best to run the choice through management just to cover your ass.

It's all relative and on a per project / client / boss basis; and not
everybody is lucky enough to pick and choose their jobs / techs and
methods. (but I am :p)

Regards

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



Re: [PHP] Please guide in selection of Framework: according to your experience

2010-03-29 Thread Nilesh Govindarajan

On 03/30/2010 01:59 AM, Daevid Vincent wrote:




-Original Message-
From: Vishal Rewari [mailto:rewari.vis...@gmail.com]
Sent: Friday, March 26, 2010 9:29 PM

I am vishal, I have recently started development in PHP
I have come across these PHP frameworks:

1. Codeigniter
2. Symphony
3. CakePHP
4. PEAR

Please guide me which one of them is *good in performance ? available
functionality ? Easy to use and configure* or the one you
would recommend according to your experience.


I was forced to use Symfony before. Hated every second of it. The company
eventually folded, no doubt in part due to the poor decision to use this
framework.

For example, using the "Symfony way" of looping over various news stories,
creating objects and the whole ORM and all that crap, it would take a
second or so per story to process. With thousands of stories this took
hours to process. We then said F-it and re-wrote the parser in straight up
PHP and now the processing took a couple of minutes.


or should I stick to native call from PHP?


Yes.

Most real developers do NOT use off-the-shelf frameworks. We generally roll
our own since no framework will do everything you're going to want or need
for your particular project, and then your stuck either trying to wedge
something in, or hoping "they" eventually catch up to your needs. They try
to be all things to all people and therefore you carry a lot of baggage and
bloat you don't want/need. And the biggest reason to avoid them is if your
project grows, now you have to find not only a skilled PHP developer, but
one that knows this additional framework and is proficient enough to use it
well. It's just a hassle in the end and puts digital handcuffs on you.
Write some wrappers for your DB calls and other useful routines and KISS.
Frameworks are great for a quick proto-type, but IMHO, why waste energy
when you'll just have to re-write it again for real. Do it right from the
start.

http://www.rapidpoll.net/8opnt1e






Yeah this is absolutely true. Frameworks are ok-ok for small apps, but 
when it comes to complex apps, it becomes to understand our own code 
itself !


--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
मेरा भारत महान !
मम भारत: महत्तम भवतु !

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