fclose

Using php to write to a log file

五迷三道 提交于 2020-11-29 02:55:18
问题 First of I am very very very very bad with php so sorry for this question I have an application in which i would like to log some debug data and through my project i make a webrequest to my site storing the information in $msg i then want to write the data to my logfile.log on the site. i first used fopen fwrite fclose, but heard that file_put_contents would be better especially as i very likely will have several users trying to write to the file at once. Here's the code: $msg = $_GET['w'];

Using php to write to a log file

醉酒当歌 提交于 2020-11-29 02:52:16
问题 First of I am very very very very bad with php so sorry for this question I have an application in which i would like to log some debug data and through my project i make a webrequest to my site storing the information in $msg i then want to write the data to my logfile.log on the site. i first used fopen fwrite fclose, but heard that file_put_contents would be better especially as i very likely will have several users trying to write to the file at once. Here's the code: $msg = $_GET['w'];

Java threads - close other threads when first thread completes

那年仲夏 提交于 2020-03-04 06:24:10
问题 Folks so my problem is that I have 3 Threads. 1Thread(Bot1) public class Bot1 implements Runnable { String name; public Bot1(String s) throws Exception{ ChatterBotFactory factory = new ChatterBotFactory(); ChatterBot bot1 = factory.create(ChatterBotType.CLEVERBOT); ChatterBotSession bot1session = bot1.createSession(); name=s; name=bot1session.think(s); } public void run(){ System.out.println("b1: "+name); } } And the others are same. Only names are Bot2 and Bot3 . But the code is almost same.

Java threads - close other threads when first thread completes

允我心安 提交于 2020-03-04 06:24:08
问题 Folks so my problem is that I have 3 Threads. 1Thread(Bot1) public class Bot1 implements Runnable { String name; public Bot1(String s) throws Exception{ ChatterBotFactory factory = new ChatterBotFactory(); ChatterBot bot1 = factory.create(ChatterBotType.CLEVERBOT); ChatterBotSession bot1session = bot1.createSession(); name=s; name=bot1session.think(s); } public void run(){ System.out.println("b1: "+name); } } And the others are same. Only names are Bot2 and Bot3 . But the code is almost same.

Why is unlink successful on an open file?

不羁的心 提交于 2020-02-15 10:12:37
问题 Why open file is deleted? On Windows Xamp, I get message "still working", but on other PHP serwer file is deleted, even if it is open and I get message "file deleted". I can delete file from FTP too, even if first script is still working :( <?php $handle = fopen("resource.txt", "x"); sleep(10); ?> <?php if (file_exists("resource.txt") && @unlink("resource.txt") === false) { echo "still worning"; exit; } else echo "file deleted"; ?> 回答1: UNIX systems typically let you do this, yes. The

C - writing output to a file

回眸只為那壹抹淺笑 提交于 2020-01-13 07:16:09
问题 EDIT: void print(const int *v, const int size) { FILE *fpIn; fpIn = fopen("char-array.txt", "a"); int i; if (v != 0) { for (i = 0; i < size; i++) { printf("%d", (int)v[i]); fprintf(fpIn, "%d\n", (int)v[i]); } perm_count++; printf("\n"); } fclose(fpIn); } I guess this is a relatively simple question :) Basically the program is using a permutation algorithm, and printing the output to standard output in the console. I also want to write the content to a file via fprintf I assume. Though I cant

fwrite() succeeded after fclose()

我怕爱的太早我们不能终老 提交于 2020-01-05 10:35:29
问题 I've encountered a strange behavior that is fwrite() succeeds after I close the stream with fclose() but the file is not overwritten as fflush() fails. My code is: int main(int argc, char* argv[]) { FILE* file = fopen("file.txt", "w"); if(!file) perror("Cannot open the file.\n"); char text[] = "1234567"; fclose(file); int count_of_written_objects = fwrite(text, sizeof(text),1, file); printf("Count of written objects into the file: %d \n", count_of_written_objects); if(count_of_written_objects

fwrite() succeeded after fclose()

為{幸葍}努か 提交于 2020-01-05 10:34:28
问题 I've encountered a strange behavior that is fwrite() succeeds after I close the stream with fclose() but the file is not overwritten as fflush() fails. My code is: int main(int argc, char* argv[]) { FILE* file = fopen("file.txt", "w"); if(!file) perror("Cannot open the file.\n"); char text[] = "1234567"; fclose(file); int count_of_written_objects = fwrite(text, sizeof(text),1, file); printf("Count of written objects into the file: %d \n", count_of_written_objects); if(count_of_written_objects

Error handling in file opening

旧街凉风 提交于 2019-12-30 18:30:08
问题 [Question 1] When I open a file into a function, generally I do something like this: int read_file (char *filename) { FILE *fin; if ( !(fin = fopen(filename, "r")) ) return 1; /* ... */ return fclose(fin); } int main () { char filename[100]; if ( read_file(filename) ) { perror(filename); exit(1); } return 0; } Generally 0 return value is for errors (right?) then I can change the previous code into: int read_file (char *filename) { FILE *fin; if ( !(fin = fopen(filename, "r")) ) return 0; /* .

Fclose a file that is already fclose

ε祈祈猫儿з 提交于 2019-12-29 07:49:50
问题 In my programm I may close a file that is already close. What happen when I do a fclose on a file already close ? And if you can't do so, how to know if a file is closed or open ? 回答1: Calling fclose twice with the same stream is undefined behaviour - most likely crash. There is no way to check if FILE* has been closed already, so the safe solution is to set pointer to NULL as soon as it is closed: fclose(fh); fh = NULL; Sources: "The value of a pointer to a FILE object is indeterminate after