Home > Archive > PHP Language > December 2006 > perl to php translation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
perl to php translation
|
|
|
| could someone traslate this small piece of perl code to php ?
many thanks
Jor
while ( -f <counter.lock> ) {
select ( undef, undef, undef, 0.3 );
}
open ( LOCKFILE, ">counter.lock" );
open (CD, "$count");
$counter = <CD>;
close (CD);
| |
|
| jor schrieb:
> could someone traslate this small piece of perl code to php ?
> many thanks
> Jor
>
> while ( -f <counter.lock> ) {
> select ( undef, undef, undef, 0.3 );
> }
>
> open ( LOCKFILE, ">counter.lock" );
> open (CD, "$count");
> $counter = <CD>;
> close (CD);
>
$fp = fopen("counter.lock", 'r');
while (!feof($fp)){
select ( undef, undef, undef, 0.3 );
}
fclose($fp);
$fp = fopen("counter.lock", 'w');
$fp = fopen($count, 'r');
$counter = fgets($fp));
fclose($fp);
-Ric
| |
| Koncept 2006-12-01, 6:57 pm |
| In article <ekpvs1$nre$1@online.de>, Ric <antispam@randometry.com>
wrote:
[color=darkred]
There is no *select* function in PHP. If you wanted to duplicate this
could, you would have to write a function to handle it. Something that
would handle the vars detailed in perldoc -f select
($nfound, $timeleft ) = select($rout=$rin,
$wout=$win,$eout=$ein,$timeout);
[color=darkred]
To handle a locked file, you can use *flock*
$fp = fopen('counter.lock','w');
if(flock($fp,LOCK_EX)){ // lock the file
// do stuff here
flock($fp, LOCK_UN); // release lock
}
[color=darkred]
If you want to read an entire file handle into a scalar, you can use
file_get_contents or the way Ric laid things out.
// Not sure what your $count var references but you do...
$counter = file_get_contents( "$count" );
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
| |
|
| Koncept wrote:
> In article <ekpvs1$nre$1@online.de>, Ric <antispam@randometry.com>
> wrote:
>
>
> There is no *select* function in PHP. If you wanted to duplicate this
> could, you would have to write a function to handle it. Something that
> would handle the vars detailed in perldoc -f select
>
> ($nfound, $timeleft ) = select($rout=$rin,
> $wout=$win,$eout=$ein,$timeout);
>
>
> To handle a locked file, you can use *flock*
> $fp = fopen('counter.lock','w');
> if(flock($fp,LOCK_EX)){ // lock the file
> // do stuff here
> flock($fp, LOCK_UN); // release lock
> }
>
> If you want to read an entire file handle into a scalar, you can use
> file_get_contents or the way Ric laid things out.
>
> // Not sure what your $count var references but you do...
> $counter = file_get_contents( "$count" );
>
> --
> Koncept <<
> "The snake that cannot shed its skin perishes. So do the spirits who are
> prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Many thanks both for the quick response!
|
|
|
|
|