Use php_stream_mkdir instead of implementing your own function.