Forum

Thread tagged as: Problem, Configuration

Resource files aren't removed from server after deleting according assets

Hello,

Resource files aren't removed from server after deleting according assets, which results in storing unnecessary unused files.

After doing a research on the subject, I've set PERCH_UNDO_BUFFER to 1, as well as PERCH_CLEAN_RESOURCES to true in config, as an experiment. It doesn't work though, nothing happens after setting the latter.

How can I 'proactively' clean up unused resource files for a fresh start? I've read asset files may be removed after 24 hours, but I'm confused if this is the case, as well I don't want to wait each time I remove an asset, but would like the according file to be removed as well inmediately.

Thank you in advance!

Kind regards, Márton Lente

Márton Lente

Márton Lente 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What steps are you following to delete the assets?

First I remove the image from the region, then I save it. Second I go to 'Assets' page in Perch, click on the image I've just removed from the region, then click, and confirm 'Delete'. The asset is then removed from the Assets panel (it isn't listed anymore), but the file itself still remains in the resources folder, which is basically my problem.

Of course, I can manually delete the remaining files myself, but that causes problems. E.g. when I upload an image again with the same filename, it has no preview. So I'm sure this isn't the way to do that.

Drew McLellan

Drew McLellan 2638 points
Perch Support

In that situation you've still got the asset in your undo history. The buffer is set to 1, so you have one level of undo. The file won't go away while it's in the history.

And what happens, if I've used Perch for content editing with default PERCH_UNDO_BUFFER so far, but now changed it to 1 (or 0)? Shall for example saving a random region multiple (more than 30) times solve my issue in theory?

Does PERCH_CLEAN_RESOURCES have any impact on the above?

I've made my suggested trial above (saving a random region multiple times just to 'stack up' history), but it didn't help. No asset file – that was earlier removed from Perch's assets – has been actually deleted from server.

Drew McLellan

Drew McLellan 2638 points
Perch Support

PERCH_CLEAN_RESOURCES needs to be true (which it is by default).

Was the asset added to Perch more than 24 hours ago? The three conditions are:

  1. PERCH_CLEAN_RESOURCES is enabled
  2. The file is not used by any content revision in the edit history stack
  3. The file was added more than 24 hours ago

Thank you for the clear explanation!

Is there a way to set another, shorter time interval, or run the 'task' manually to avoid waiting 24 hours? Sometimes it'd be nice to have full control on clearing unused resources.

I guess I could set server time a day forward to achieve the above, but there may be more direct solution...

Thank you in advance!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Why would you need to do that? Are you running that close to your available disc space limit?

No, it's just partly because of disc space limit. It's because I use an image naming strategy e.g. sample-image-1.jpg, sample-image-2.jpg etc. I want my images to be able to be downloaded with the exact filename I've named them. When I work on an image locally, resave it, then upload it again with the same file name to the server e.g. sample-image-1.jpg, it gets renamed because of unremoved assets to sample-image-1-1.jpg. The more I repeat this step, and especially when there is a set of images, filenames get messy.

The main problem is, that 24 hours passed, but no resources has been deleted despite of my trials. Is there a chance that it's because of some wrong server settings? I'm on Windows, XAMPP. Here is my extended Perch information:

    Perch: 3.0.13
    Production mode: Production (100)
    Installed apps: content (3.0.13), assets (3.0.13), categories (3.0.13), perch_forms (1.10), chirp_seo (1.2.1), perch_mailchimp (3.1)
    DB driver: PDO
    DB tables: perch3_categories (0), perch3_category_counts (0), perch3_category_sets (0), perch3_chirp_seo (3), perch3_chirp_seo_scores (7), perch3_content_index (3582), perch3_content_items (545), perch3_content_regions (40), perch3_forms (1), perch3_forms_responses (4), perch3_mailchimp_campaigns (0), perch3_mailchimp_imports (0), perch3_mailchimp_lists (1), perch3_mailchimp_subscribers (0), perch3_mailchimp_subscriptions (0), perch3_mailchimp_webhooks (1), perch3_menu_items (11), perch3_navigation (0), perch3_navigation_pages (0), perch3_page_templates (1), perch3_pages (7), perch3_resource_log (615), perch3_resource_tags (0), perch3_resources (174), perch3_resources_to_tags (0), perch3_settings (26), perch3_user_passwords (1), perch3_user_privileges (35), perch3_user_role_privileges (2), perch3_user_roles (2), perch3_users (1)
    Users: 1
    App runtimes:

    <?php
        $apps_list = [ 
          'perch_forms',
          'perch_mailchimp',
        ];

    Scheduled tasks for perch_mailchimp: import_data (1 mins)
    Editor plug-ins:
    H1: 68477001cd6717ac098a6fcaffaa8f6e
    L1: d37fdf621974b85fa57992b7d98e70e4
    F1: 3b606135b33e6a102526838f4152a807
    headerColour: #ffffff
    content_singlePageEdit: 1
    helpURL:
    hideBranding: 0
    content_collapseList: 1
    lang: en-gb
    installedAt: 3.0.13
    update_3.0.13: done
    latest_version:
    on_sale_version: 3.0.14
    headerScheme: light
    perch_mailchimp_api_key: 79084092cdeff89c9d8175d1c8fcb333-us17
    perch_mailchimp_campaign_url: /mailchimp/campaign/{campaignSlug}
    dashboard: 0
    sidebar_back_link: 0
    hide_pwd_reset: 0
    keyboardShortcuts: 0
    content_hideNonEditableRegions: 0
    content_frontend_edit: 1
    content_skip_region_list: 0
    assets_restrict_buckets: 0
    perch_mailchimp_secret: 7d0641a
    chirp_update: 1.2.1
    chirp_seo_license_key: 5P12X-O06CX-1KMYE-0XW05
    siteURL: https://martonlente.com
    PERCH_DEVELOPMENT: 10
    PERCH_STAGING: 50
    PERCH_PRODUCTION: 100
    PERCH_DB_USERNAME: root
    PERCH_DB_SERVER: localhost
    PERCH_DB_DATABASE: db_martonlente
    PERCH_DB_PREFIX: perch3_
    PERCH_TZ: UTC
    PERCH_EMAIL_FROM: form@martonlente.com
    PERCH_EMAIL_FROM_NAME: Márton Lente
    PERCH_EMAIL_METHOD: smtp
    PERCH_EMAIL_HOST: mail.martonlente.com
    PERCH_EMAIL_AUTH: 1
    PERCH_EMAIL_SECURE: ssl
    PERCH_EMAIL_PORT: 465
    PERCH_EMAIL_USERNAME: form@martonlente.com
    PERCH_LOGINPATH: /perch
    PERCH_PATH: E:\1708_personal-branding\31_Web\perch
    PERCH_CORE: E:\1708_personal-branding\31_Web\perch\core
    PERCH_RESFILEPATH: E:\1708_personal-branding\31_Web\perch\resources
    PERCH_RESPATH: /perch/resources
    PERCH_HTML5: 1
    PERCH_UNDO_BUFFER: 1
    PERCH_RUNWAY:
    PERCH_ERROR_MODE: DIE
    PERCH_DATE_LONG: %d %B %Y
    PERCH_DATE_SHORT: %d %b %Y
    PERCH_TIME_SHORT: %H:%M
    PERCH_TIME_LONG: %H:%M:%S
    PERCH_RUNWAY_ROUTED:
    PERCH_STRONG_PASSWORDS:
    PERCH_ASSET_VERSION: f704e7442d11292c99b5
    PERCH_DEBUG:
    PERCH_PREVIEW_ARG: preview
    PERCH_TEMPLATE_PATH: E:\1708_personal-branding\31_Web\perch\templates
    PERCH_TEMPLATE_FILTERS:
    PERCH_DEFAULT_DOC: index.php
    PERCH_DEFAULT_EXT: .php
    PERCH_PRODUCTION_MODE: 100
    PERCH_XHTML_MARKUP:
    PERCH_RWD: 1
    PERCH_HTML_ENTITIES:
    PERCH_SSL:
    PERCH_STRIPSLASHES:
    PERCH_PROGRESSIVE_FLUSH: 1
    PERCH_PARANOID:
    PERCH_FORCE_SECURE_COOKIES:
    PERCH_DEFAULT_BUCKET: default
    PERCH_TRANSLATION_ASSIST:
    PERCH_PASSWORD_MIN_LENGTH: 6
    PERCH_MAX_FAILED_LOGINS: 10
    PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
    PERCH_VERIFY_UPLOADS:
    PERCH_PRIV_ASSIST:
    PERCH_CUSTOM_EDITOR_CONFIGS:
    PERCH_ENABLE_EXIF: 1
    PERCH_AUTH_PLUGIN:
    PERCH_DB_CHARSET: utf8
    PERCH_DB_PORT:
    PERCH_DB_SOCKET:
    PERCH_APPS_EDITOR_PLUGIN: markitup
    PERCH_APPS_EDITOR_MARKUP_LANGUAGE: markdown

Hosting settings

    PHP: 5.6.30
    Zend: 2.6.0
    OS: WINNT
    SAPI: apache2handler
    Safe mode: not detected
    MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
    MySQL server: 5.5.5-10.1.21-MariaDB
    Free disk space: 62.55 GB
    Extensions: Core, bcmath, calendar, ctype, date, ereg, filter, ftp, hash, iconv, json, mcrypt, SPL, odbc, pcre, Reflection, session, standard, mysqlnd, tokenizer, zip, zlib, libxml, dom, PDO, bz2, SimpleXML, wddx, xml, xmlreader, xmlwriter, apache2handler, openssl, curl, fileinfo, gd, gettext, mbstring, exif, mysql, mysqli, pdo_mysql, pdo_sqlite, Phar, mhash
    GD: Yes
    ImageMagick: No
    PHP max upload size: 4M
    PHP max form post size: 16M
    PHP memory limit: 256M
    Total max uploadable file size: 4M
    Resource folder writeable: Yes
    Session timeout: 24 minutes
    Native JSON: Yes
    Filter functions: Yes
    Transliteration functions: No
    MIBDIRS: D:/xampp/php/extras/mibs
    MYSQL_HOME: \xampp\mysql\bin
    OPENSSL_CONF: D:/xampp/apache/bin/openssl.cnf
    PHP_PEAR_SYSCONF_DIR: \xampp\php
    PHPRC: \xampp\php
    TMP: \xampp\tmp
    HTTP_HOST: martonlente.l1
    HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
    HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    HTTP_ACCEPT_LANGUAGE: hu-HU,hu;q=0.8,en-US;q=0.5,en;q=0.3
    HTTP_ACCEPT_ENCODING: gzip, deflate
    HTTP_REFERER: https://martonlente.l1/perch/core/settings/diagnostics/
    HTTP_COOKIE: cmsa=1; PHPSESSID=m2315hg7ftleoig0i7t4263lg6
    HTTP_DNT: 1
    HTTP_CONNECTION: keep-alive
    HTTP_UPGRADE_INSECURE_REQUESTS: 1
    PATH: C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files (x86)\Extensis\Suitcase Fusion\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Calibre2\;C:\Users\martonlente\AppData\Local\Microsoft\WindowsApps;
    SystemRoot: C:\WINDOWS
    COMSPEC: C:\WINDOWS\system32\cmd.exe
    PATHEXT: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
    WINDIR: C:\WINDOWS
    SERVER_SIGNATURE: <address>Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 Server at martonlente.l1 Port 80</address>
    SERVER_SOFTWARE: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
    SERVER_NAME: martonlente.l1
    SERVER_ADDR: 127.0.0.1
    SERVER_PORT: 80
    REMOTE_ADDR: 127.0.0.1
    DOCUMENT_ROOT: E:/1708_personal-branding/31_Web
    REQUEST_SCHEME: http
    CONTEXT_DOCUMENT_ROOT: E:/1708_personal-branding/31_Web
    SERVER_ADMIN: postmaster@localhost
    SCRIPT_FILENAME: E:/1708_personal-branding/31_Web/perch/core/settings/diagnostics/index.php
    REMOTE_PORT: 61351
    GATEWAY_INTERFACE: CGI/1.1
    SERVER_PROTOCOL: HTTP/1.1
    REQUEST_METHOD: GET
    QUERY_STRING: extended
    REQUEST_URI: /perch/core/settings/diagnostics/?extended
    SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
    PHP_SELF: /perch/core/settings/diagnostics/index.php
    REQUEST_TIME_FLOAT: 1519038631.128
    REQUEST_TIME: 1519038631

Thank you in advance!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you re-saved your content to trigger the cleanup?

Yes I have, the according region and others too, several – obviously more than 30 – times during my trials.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't know then. If there's any doubt whether a file is safe to delete or not, Perch doesn't delete it. Things should eventually just wash out with the majority of unused files eventually being removed.

It sounds like you have requirements of wanting to use software to manage your assets, but also manage the filenames yourself. For most CMSs those requirements will conflict, as the system needs to implement revision control as well as making sure that multiple users don't overwrite each others files, and that caches are busted when a new version of a file is uploaded.

I don't have a solution for your requirements - it's not a problem we're trying to solve with Perch.

Thank you for your help, no problem. My issue is basically that my unused resources aren't deleted automatically, though – based on the docs – they should. It has nothing to do with the naming of files – I just provided that for understanding the context.

I'll run some tests on my production server too – I'll share here if I find what the problem was.

Have a nice day!

Hello,

Though I couldn't force automatic cleanup of resources, I found a manual way I was looking for, that solved my issue for extreme resources-control, that I share below:

  1. Make sure the resources you want to clean up aren't used in Perch.
  2. Manually delete the unused resource file(s) from Perch's resources folder.
  3. Search for the according filename(s) within perch3_resources table e.g. in phpMyAdmin, and delete the according row(s) too.
  4. You have manually-cleaned the resources folder, and can issue a 'fresh start'.

I've tested this, and it works for my case.