Connecting Tech Pros Worldwide Forums | Help | Site Map

Coverting perl to php

Bill H
Guest
 
Posts: n/a
#1: Sep 3 '08
Hi

I have some perl code that lets me request different things, images,
audio, etc and it will output the correct mime type header and
"stream" the file to a browser (instead of a hard link to the image
itself). I am bout ready to convert it to php but wonder if there are
already built in commands to do this. If so can someone give me a
pointer or 2 where to look in the manual (I am not that good with
search engines).

TYI

Bill H
C. (http://symcbean.blogspot.com/)
Guest
 
Posts: n/a
#2: Sep 4 '08

re: Coverting perl to php


On 3 Sep, 20:25, Bill H <b...@ts1000.uswrote:
Quote:
Hi
>
I have some perl code that lets me request different things, images,
audio, etc and it will output the correct mime type header and
"stream" the file to a browser (instead of a hard link to the image
itself). I am bout ready to convert it to php but wonder if there are
already built in commands to do this. If so can someone give me a
pointer or 2 where to look in the manual (I am not that good with
search engines).
>
TYI
>
Bill H
<?php

$src="/path/to/some_file.mp3";

if (file_exists($src)) {
header('Content-type: audio/mpeg');
readfile($src);
} else {
header('HTTP/1.0 404 Not Found');
print "Whoops!\n";
}

?>

Note that the above is not actually streaming - just writing the file
to the browser. Have a google for progresive download for how to
emulate streaming across HTTP.

As for determining mime-type for a arbitary file - it depends on your
OS and webserver - but most have a mime-types file which maps file
extensions to mime types. Or, if you're running on a Unix/Linux system
you can call the 'file' command from PHP to get the mime-type (see man
file for more info).

C.
Jeff
Guest
 
Posts: n/a
#3: Sep 4 '08

re: Coverting perl to php


<snip>
Quote:
>
@OP: Why are you rewriting in PHP? If it works in Perl, and if it's what
you know, rewriting to PHP would be inefficient, and counter-intuitive.
Pretty much all hosting companies should have Perl available.
Yes, they do.

But I was losing work, with perl. And I think that little development
is going on in perl.

I have a series of utilities (a perl module that I'm writing as a php
class) that do the normal sorts of stuff and since all new code is in
php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend
that said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Jeff
Quote:
>
--
Curtis
Curtis
Guest
 
Posts: n/a
#4: Sep 5 '08

re: Coverting perl to php


Jeff wrote:
Quote:
<snip>
Quote:
>>
>@OP: Why are you rewriting in PHP? If it works in Perl, and if it's
>what you know, rewriting to PHP would be inefficient, and
>counter-intuitive. Pretty much all hosting companies should have Perl
>available.
>
Yes, they do.
>
But I was losing work, with perl. And I think that little development
is going on in perl.
I see, that's unfortunate. However, the Perl community is very much
alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.
Quote:
I have a series of utilities (a perl module that I'm writing as a php
class) that do the normal sorts of stuff and since all new code is in
php, I need the utility to match. I'm not rewriting existing apps.
>
Gives me the chance to improve on what I had done. I had a friend that
said that you should throw out the first two code versions!
>
I much prefer the php class idea over the perl module.
Fair enough. :-)

--
Curtis
Jeff
Guest
 
Posts: n/a
#5: Sep 5 '08

re: Coverting perl to php


Curtis wrote:
Quote:
Jeff wrote:
Quote:
><snip>
Quote:
>>>
>>@OP: Why are you rewriting in PHP? If it works in Perl, and if it's
>>what you know, rewriting to PHP would be inefficient, and
>>counter-intuitive. Pretty much all hosting companies should have Perl
>>available.
>>
> Yes, they do.
>>
> But I was losing work, with perl. And I think that little
>development is going on in perl.
>
I see, that's unfortunate.
I thought so. I thought I held out too long. Far too long.

However, the Perl community is very much
Quote:
alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.
No kidding! I really thought that was a never going to happen. Is it
going to be written in C++ instead of C?

OK, I just googled, and I saw nothing post 2005 :-(

I've always liked the brevity of perl. It's written for speed (in
programming) and as they say, more than one way to do it. I never found
anything I couldn't do that I wanted to do. And DBI rocks!
Quote:
>
Quote:
> I have a series of utilities (a perl module that I'm writing as a
>php class) that do the normal sorts of stuff and since all new code is
>in php, I need the utility to match. I'm not rewriting existing apps.
>>
> Gives me the chance to improve on what I had done. I had a friend
>that said that you should throw out the first two code versions!
>>
> I much prefer the php class idea over the perl module.
>
Fair enough. :-)
The only thing I can say now is that I'm glad I never learned php4
specific stuff! Now if php6 would just toss in some of my favorite perl
bits...

Jeff
Quote:
>
--
Curtis
Curtis
Guest
 
Posts: n/a
#6: Sep 7 '08

re: Coverting perl to php


Jeff wrote:
Quote:
Curtis wrote:
Quote:
>Jeff wrote:
Quote:
>><snip>
>>>>
>>>@OP: Why are you rewriting in PHP? If it works in Perl, and if it's
>>>what you know, rewriting to PHP would be inefficient, and
>>>counter-intuitive. Pretty much all hosting companies should have
>>>Perl available.
>>>
>> Yes, they do.
>>>
>> But I was losing work, with perl. And I think that little
>>development is going on in perl.
>>
>I see, that's unfortunate.
>
I thought so. I thought I held out too long. Far too long.
>
However, the Perl community is very much
Quote:
>alive, and many new things are on the way for Perl 6; so it is
>definitely still under active development.
>
No kidding! I really thought that was a never going to happen. Is it
going to be written in C++ instead of C?
>
OK, I just googled, and I saw nothing post 2005 :-(
Perl 6 has been under development for almost 10 years, apparently. A
brief Google search turned up this FAQ about Perl 6:

<URL:http://dev.perl.org/perl6/faq.html>

As for the community, if you try perlmonks or other such places, I
would imagine them quite active. I'm not really active in the Perl
community, so I can't say for sure.

Perl 5 is very stable, so changes are quite rare and minimal.
Quote:
I've always liked the brevity of perl. It's written for speed (in
programming) and as they say, more than one way to do it. I never found
anything I couldn't do that I wanted to do. And DBI rocks!
Quote:
>>
Quote:
>> I have a series of utilities (a perl module that I'm writing as a
>>php class) that do the normal sorts of stuff and since all new code
>>is in php, I need the utility to match. I'm not rewriting existing apps.
>>>
>> Gives me the chance to improve on what I had done. I had a friend
>>that said that you should throw out the first two code versions!
>>>
>> I much prefer the php class idea over the perl module.
>>
>Fair enough. :-)
>
The only thing I can say now is that I'm glad I never learned php4
specific stuff! Now if php6 would just toss in some of my favorite perl
bits...
>
Jeff
The last I read of PHP 6 features was from a meeting between the devs
in 2005, although you can download snaps of the current state of PHP 6
right now.

--
Curtis
Closed Thread


Similar PHP bytes