This is a discussion on perl to php translation within the alt.comp.lang.php forums, part of the PHP Programming Forums category; could someone traslate this small piece of perl code to php ? many thanks Jor while ( -f <counter.lock> ) { ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
In article <ekpvs1$nre$1@online.de>, Ric <antispam@randometry.com>
wrote: > > could someone traslate this small piece of perl code to php ? > > many thanks > > Jor > > > > select ( undef, undef, undef, 0.3 ); 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); > > open ( LOCKFILE, ">counter.lock" ); 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 } > > $counter = <CD>; 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: > > > > could someone traslate this small piece of perl code to php ? > > > many thanks > > > Jor > > > > > > select ( undef, undef, undef, 0.3 ); > > 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); > > > > open ( LOCKFILE, ">counter.lock" ); > > 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 > } > > > > $counter = <CD>; > 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! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|