Stream_flush in not being called while using stream wrapper I've created a stream wrapper foo:// and when I am using this wrapper and my file moved successfully but the flush_stream function is not called I don't why I also checked for the public:// stream wrapper and It calls the flush_stream function after moving file.

I backtracked the code while running for public:// stream wrapper I got this output

Array
(
[0] =&gt; Array
    (
        [function] =&gt; stream_flush
        [class] =&gt; DrupalLocalStreamWrapper
        [object] =&gt; DrupalPublicStreamWrapper Object
            (
                [context] =&gt; 
                [handle] =&gt; Resource id #11
                [uri:protected] =&gt; public://a1a1211127_aa_0.jpg
            )

        [type] =&gt; -&gt;
        [args] =&gt; Array
            (
            )

    )

[1] =&gt; Array
    (
        [file] =&gt; /var/www/html/includes/file.inc
        [line] =&gt; 1633
        [function] =&gt; move_uploaded_file
        [args] =&gt; Array
            (
                [0] =&gt; /tmp/phpPaIdAn
                [1] =&gt; public://a1a1211127_aa_0.jpg
            )

    )
[2] =&gt; Array
    (
        [file] =&gt; /var/www/html/includes/file.inc
        [line] =&gt; 1585
        [function] =&gt; drupal_move_uploaded_file
        [args] =&gt; Array
            (
                [0] =&gt; /tmp/phpPaIdAn
                [1] =&gt; public://a1a1211127_aa_0.jpg
            )

    )


It means stream_flush is called after the move_uploaded_file function. But in my case the move_uploaded_file function is called but stream_flush is not.

Any idea why?
I Just changed the stream wrapper type to STREAM_WRAPPERS_LOCAL_NORMAL and implements the chmod function and it works seamlessly.