title: PHP extension returns different system errors fom CLI and apache2 module
body: <p>This is a code fragment of a function inside a PHP extension. The long parameter passed "fd" is irrelevant and not used. </p>
  
  <pre><code>PHP_FUNCTION(crtest) { int fd ; FILE *fp ;
  
      if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &amp;fd) == FAILURE) {
          RETURN_NULL();
      }
  
      fp = fopen("/usr/pkg/php-5.6.30/ext/cisam/tests/tfile", "w") ;
      php_printf("fopen   : %d\n", errno) ;
      fprintf(fp, "%s\n", "/usr/pkg/php-5.6.30/ext/cisam/tests/tfile") ;
      php_printf("fprintf : %d\n", errno) ;
      fclose(fp) ;
      php_printf("fclose  : %d\n", errno) ;
  
      RETURN_LONG(errno) ;
  
  }
  </code></pre>
  
  <p>The strange thing here is:</p>
  
  <ul>
  <li>When running from cli the function ALWAYS returns error 25 (ENOTTY)</li>
  <li>When running from apache2 module on all operations error 2 (ENOFILE) is returned. (Permissions for the web server are fixed).</li>
  </ul>
  
  <p>BUT in BOTH CASES the operation is COMPLETED NORMALLY besides the error. Any help or hint?</p>
  
  <p>PHP is 5.6.30</p>