php-general Digest 30 Mar 2010 12:05:08 -0000 Issue 6666
Topics (messages 303603 through 303609):
Re: is there any setting to declare the member variables in constructor?
303603 by: Richard Quadling
303604 by: solo hsi
Re: Please guide in selection of Framework: according to your experience
303605 by: Daevid Vincent
303607 by: Nathan Rixham
303608 by: Nilesh Govindarajan
Re: how to provide download of files mow in documentroot
303606 by: Nathan Rixham
Re: Zip and text files generated are corrupted
303609 by: Bastien Helders
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 ---
On 29 March 2010 16:47, solo hsi <xzy...@gmail.com> 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
> <rquadl...@googlemail.com> wrote:
>> On 27 March 2010 17:50, solo hsi <xzy...@gmail.com> 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
--- End Message ---
--- Begin Message ---
i have done my work, replaced fpdf with tcpdf, just by using fpdi:)
On Tue, Mar 30, 2010 at 12:12 AM, Richard Quadling
<rquadl...@googlemail.com> wrote:
> On 29 March 2010 16:47, solo hsi <xzy...@gmail.com> 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
>> <rquadl...@googlemail.com> wrote:
>>> On 27 March 2010 17:50, solo hsi <xzy...@gmail.com> 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)
--- End Message ---
--- Begin Message ---
> -----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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
मेरा भारत महान !
मम भारत: महत्तम भवतु !
--- End Message ---
--- Begin Message ---
Jan G.B. wrote:
> 2010/3/29 Nathan Rixham <nrix...@gmail.com>
>
>> Jan G.B. wrote:
>>> Top posting sucks, so I'll answer the post somewhere down there.
>>> <SCNR>
>>>
>>> 2010/3/29 Devendra Jadhav <devendra...@gmail.com>
>>>
>>>> Then you can do file_get_contents within PHP. or any file handling
>>>> mechanism.
>>>>>> On Mon, Mar 29, 2010 at 1:00 AM, ebhakt <i...@ebhakt.com> 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
>>> <?php
>>> $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 <Directory /path/to> 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!
--- End Message ---
--- Begin Message ---
I've come to realize something, but I'm not sure if I could be right:
Maybe the instructions are interrupted because there is a lack of virtual
memory. I mean is there not a limit to the memory the script can use? It
would explain why the script goes on, as when the instruction is
interrupted, all the memory taken by it is released.
I don't know if I was clear about what I wanted to say...
2010/3/29 Bastien Helders <eldroskan...@gmail.com>
> >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
>
> <?php
> //This is this command that got interrupted and thus create the unexpected
> end-of-archive
> //To note is that the $previous_patch is retrieved from another file server
> copy($previous_patch,$zipname);
>
> //I go up in the file system, so that build/patchname doesn't appear in the
> paths in the zip archive.
> chdir('build/'.$patchname);
>
> //Foreach new folder add it to the copied patch
> foreach($folders_added as $folder){
> $command = 'zip -gr ../../' . $zipname . '
> software/hfFolders/'.$folder.'/* 2>&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
>
> <?php
> //I go up in the file system, so that build/patchname doesn't appear in the
> paths in the zip archive.
> chdir('build/'.$patchname);
> $command = 'zip -r ../../' . $zipname . ' * 2>&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 <rquadl...@googlemail.com>
>
>> On 26 March 2010 15:20, Bastien Helders <eldroskan...@gmail.com> 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 <rquadl...@googlemail.com>
>> >>
>> >> On 26 March 2010 12:21, Bastien Helders <eldroskan...@gmail.com>
>> 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:
>> >> >
>> >> > <STDERR>
>> >> > zip warning: ../../build/Patch-6-3-2_Q3P15.zip not found or empty
>> >> >
>> >> > zip error: Internal logic error (write error on zip file)
>> >> > </STDERR>
>> >> >
>> >> > The funny thing is, that now it is throwing status 5: "a severe error
>> in
>> >> > the
>> >> > zipfile format was
>> >> > detected. Processing probably failed immediately." 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:
>> >> >
>> >> > <STDERR>
>> >> > zip error: Internal logic error (write error on zip file)
>> >> > </STDERR>
>> >> >
>> >> > 2) The error messages of the second scenario doesn't surprise me
>> much:
>> >> >
>> >> > <STDERR>
>> >> > zip error: Unexpected end of zip file (build/Patch-6-3-2_Q3P15.zip)
>> >> > </STDERR>
>> >> >
>> >> > 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-exchange.com/becomeAnExpert.jsp
>> >> Zend Certified Engineer :
>> http://zend.com/zce.php?c=ZEND002498&r=213474731
>> >> ZOPA : http://uk.zopa.com/member/RQuadling
>> >
>> >
>> >
>> > --
>> > haXe - an open source web programming language
>> > http://haxe.org
>> >
>>
>> I'm not sure. What is the exact command you are using?
>>
>> I wonder if the zipArchive route would be easier.
>>
>>
>> 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
>> )
>>
>> Can you run the command from the shell directly without any problems.
>> And run it repeatedly.
>>
>>
>> --
>> -----
>> 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
>>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
--
haXe - an open source web programming language
http://haxe.org
--- End Message ---