在临时文件夹中创建的很多临时魔法文件 [英] lot of temp magick files created in temporary folder

查看:475
本文介绍了在临时文件夹中创建的很多临时魔法文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 imagick 库来调整和处理http处理程序中的图像。哪个不在 / tmp 文件夹中写任何内容。但是因为我可以在该文件夹中创建大量这些文件,并且它的大小每天都在增长,目前它正在消耗大约90%的分区大小。此外,我也无法阅读他们的内容。那么,为什么要创建这些文件,一段时间后它们会被删除,还是我需要手动删除它们。

I am using the imagick library to resizing and cropping the images in a http handler. Which doesn't write anything in /tmp folder. But as i can a lot of these files are being created in that folder and it's size is growing on a daily basis and currently it's consuming around 90% of partition size. Moreover, i am not able to read their content also. So, why these files are being created and would they be delete after a while or do i need to manually delete them.

    -rw------- 1 ubuntu ubuntu   16M Feb 22 09:46 magick-d6ascKJV
    -rw------- 1 ubuntu ubuntu   16M Feb 22 09:46 magick-46ccZIfq
    -rw------- 1 ubuntu ubuntu  1.8M Feb 22 09:47 magick-vUET7vyh
    -rw------- 1 ubuntu ubuntu  1.8M Feb 22 09:47 magick-OLkGWTX8
    -rw------- 1 ubuntu ubuntu   15M Feb 22 09:48 magick-LNMV7YvE
    -rw------- 1 ubuntu ubuntu   16M Feb 22 09:49 magick-0LMYt6Kc
    -rw------- 1 ubuntu ubuntu   16M Feb 22 09:50 magick-ceNxX5CY
    -rw------- 1 ubuntu ubuntu   16M Feb 22 09:50 magick-nQ1M3y6I

修改:

我的http处理程序中没有使用以下两行。原因是我无法找到任何解释。而且,go http处理程序工作正常。那么,这些陈述的目的是什么?

I am not using the following two lines in my http Handler. Reason being i couldn't find any explanation to do so. Moreover, the go http handler works fine. So, what is the purpose of these statements?

imagick.Initialize() 
defer imagick.Terminate()

我假设有一些理由将它们包含在代码中。所以,在去http处理程序。它应该包含在 func main()里面还是 serveHTTP 里面?

I am assuming there would be some reason to include them in the code. So, in go http handler. Where it should be included inside func main() or inside serveHTTP ?

func main() {                                           
    myMux := http.NewServeMux()
    myMux.HandleFunc("/", serveHTTP)

    if err := http.ListenAndServe(":8085", myMux); err != nil {
        logFatal("Error when starting or running http server: %v", err)
    }       

}

func serveHTTP(w http.ResponseWriter, r *http.Request) {

}


推荐答案

实际上它应该包含在 func main()中,而不是在
func serveHTTP中()。对于长时间运行的应用程序,它应该被调用一次,它解决了我的问题。

Actually it should be included in the func main() not in the func serveHTTP(). It is meant to be called once for a long running application and it solved my problem.

func main() {   

    imagick.Initialize() 
    defer imagick.Terminate()                                        
    myMux := http.NewServeMux()
    myMux.HandleFunc("/", serveHTTP)

    if err := http.ListenAndServe(":8085", myMux); err != nil {
        logFatal("Error when starting or running http server: %v", err)
    }       

}

func serveHTTP(w http.ResponseWriter, r *http.Request) {

}

这篇关于在临时文件夹中创建的很多临时魔法文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆