Re: Re: problem with fopen

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: Re: problem with fopen
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-618@lists.php.net to get a copy of this message
And since you are using Apache2 likely with the Worker mpm you are going to need to make this threadsafe as well. Unless you atomically create a unique filename to write to in each thread, you will be stepping on yourself here. -Rasmus On Thu, 6 May 2004, Sara Golemon wrote: > Please handle file operations via the streams layer. Apart from allowing > your extension to interoperate with wrappers this approach ensures that > safe_mode and basedir restrictions are properly applied. A sample use > (following your original sample) would be: > > php_stream *stream; > char *file = "/tmp/neo/tmp_file1"; > char *inbuf = "some message"; > int sizeofinput = strlen("some message"); > > stream = php_stream_open_wrapper(file, "wb", 0, NULL); > if (!stream) { > php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file for > writing."); > RETURN_FALSE; > } > php_stream_write(stream, inbuf, sizeofinput); > php_stream_close(stream); > > Consult main/php_streams.h for a more complete list of API functions. > > ----- Original Message ----- > From: "Animesh Bansriyar" <animesh@neolinuxsolutions.com> > Newsgroups: php.pecl.dev > To: "PECL DEV" <pecl-dev@lists.php.net> > Sent: Thursday, May 06, 2004 10:36 PM > Subject: problem with fopen > > > > Hello All, > > > > I am writing a custom PHP extension on Debian GNU/Linux with > > Apache2.0.46/PHP-5.0.0RC1 wherein I need to open a file, write to it and > > save to disk. I am able to open the file using VCWD_FOPEN, but when I > > try to close the file handle, PHP/Apache crashed with "The document > > contains no data" error on the browser and segfaults when I run it from > > the command line. The sample code is > > > > FILE *infile; > > char *dir = "/tmp/neo"; > > char *file = "/tmp/neo/tmp_file1"; > > infile = VCWD_FOPEN(file,"wb"); > > fwrite(inbuf, sizeofinput, 1, infile); > > fclose(infile); > > > > I need to use fopen, fwrite while opening a file, writing to it and > > saving it. If you can show me some pointers/sample code or some > > suggesstions on this, I would be so very thankful. I tried reviewing > > some code on the standard PHP extensions but by the end of it I got very > > confused. > > > > Thanks in advance, > > Regards, > > Animesh > > -- > > Animesh Bansriyar <animesh@neolinuxsolutions.com> > > http://neolinuxsolutions.com, +91-651-3112497, 3122401. > > > > Linux Intranet/Internet Servers, Specialised E-mail Setups, > > Enterprise Database and Directory Services, Linux Application > > Development and Commercial Support for Free/OpenSource Software > > -- > PECL development discussion Mailing List (http://pecl.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.pecl.dev (#618) next »