Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 882135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:22:47+00:00 2026-05-15T12:22:47+00:00

This is a question from PHP zend exam, Using flock() to lock a stream

  • 0

This is a question from PHP zend exam,

Using flock() to lock a stream is only assured to work under what circumstances?

  • When running in a Linux environment local filesystem
  • When accessing the stream of the local filesystem
  • When running in a Windows environment and accessing a share
  • When accessing a bi-directional stream
  • When accessing a read-only stream
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:22:48+00:00Added an answer on May 15, 2026 at 12:22 pm

    A stream has this set of operations – write, read, close, flush (mandatory, even if they are no ops) and seek, cast, stat, set_option (optional). When you request a file lock, the set_option operation is called.

    Just from here, you can see that being bi-directional or read-only has nothing to do with this. One could implement an arbitrary wrapper, make the writes and reads have some effect and yet not implement set_option, because it’s optional. Likewise, one could implement a no-op write operation and yet handle file locks in my set_option implementation. Running in a Linux environment is also irrelevant, since what matters is what the stream supports.

    (NOTE: I’m not sure what “running in a Linux environment local filesystem” means. I admitted it means “running PHP from the local filesystem in a Linux environment” as opposed to e.g. “running PHP from an AFS filesystem in a Linux environment”. It if means “accessing a stream that backs the local filesyste in a Linux environment”, this is probably the correct answer, given the manual warning described below).

    The remaining questions involve the STDIO streams. Now, when checking if a stream supports blocking with stream_supports_lock, PHP doesn’t actually try a flock, it passes the set_option operation a special value that queries “does this stream support file locking”? The STDIO stream operation always responds it does, so it would appear that all the two remaining answers are correct.

    However, the fact the set_option operation claims it supports file locking doesn’t make it true. When you actually try to acquire the lock, it may fail. So when is it guaranteed to work? Surely not Windows shares, since these can be backed by almost anything. We’re left with “on the local filesystem”. So the answer is, by elimination

    When accessing the stream of the local filesystem

    Note, however, the (admittedly outdated) warning in the manual:

    flock() is not supported on antiquated filesystems like FAT and its derivates and will therefore always return FALSE under this [sic] environments (this is especially true for Windows 98 users).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to another question I wrote: Trouble using DOTNET from PHP.
I have this question from the Zend PHP study guide and can't find a
Please note that this question is from 2008 and now is of only historic
I am using MVC in PHP based Zend Framework. This is more of a
This question is mainly geared towards Zend in PHP, although it certainly applies to
This is a continuation of this question from yesterday . Here are my three
I got this question from my cousin: What will be the best way to
Unfortunately I am not writing this question from my Developing PC so I might
This question results from hours of googling highstocks, zoom, extremes, ranges, and every other
This question stems from Hartl's Rails Tutorial (progressed in chapter 9) - sorry if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.