guys, always remember that every function that *generates output* could cause a
bailout if ignore_user_abort is set to false (and the user _aborts_ the
connection). in this case a longjump will be performed and our function (in
this case readfile) will have no chance to clean-up. having said that it's a
good idea to register all opened files using REGISTER_RESOURCE - that way the
engine will make sure they get closed on request end.
int size=0;
int use_include_path=0;
int issock=0, socketd=0;
+ int rsrc_id;
/* check args */
switch (ARG_COUNT(ht)) {
}
RETURN_FALSE;
}
- if (php_header()) {
- size = php_passthru_fd(socketd, fp, issock);
- }
+
if (issock) {
- SOCK_FCLOSE(socketd);
+ int *sock=emalloc(sizeof(int));
+ *sock = socketd;
+ rsrc_id = ZEND_REGISTER_RESOURCE(NULL,sock,php_file_le_socket());
} else {
- fclose(fp);
+ rsrc_id = ZEND_REGISTER_RESOURCE(NULL,fp,php_file_le_fopen());
}
+
+ if (php_header()) {
+ size = php_passthru_fd(socketd, fp, issock);
+ }
+
+ zend_list_delete(rsrc_id);
+
RETURN_LONG(size);
}