{"id":6953,"date":"2021-04-16T07:01:43","date_gmt":"2021-04-16T07:01:43","guid":{"rendered":"https:\/\/www.bodhost.com\/kb\/?p=6953"},"modified":"2026-02-26T14:03:09","modified_gmt":"2026-02-26T14:03:09","slug":"how-to-defragment-php-session-files","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/","title":{"rendered":"How to Defragment PHP Session Files"},"content":{"rendered":"\r\n<h4 class=\"wp-block-heading\">What is PHP?<\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">PHP is a popular open-source script language that incorporated into HTML and is ideal for Web development. PHP is a server-side scripting language for creating dynamic and interactive Web pages.<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><strong>Description:<\/strong><\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In certain cases, if a PHP web application is not configured properly, it will begin to accumulate unwanted PHP Session files, which will increase in size and ultimately lead to a partition&#8217;s disc usage being maxed out.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This is popular in CMSs like <strong>WordPress<\/strong> or <strong>Joomla<\/strong>, where plugins cannot delete unused PHP Session files according to efficient coding standards.<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\"><strong>Resolution:<\/strong><\/h4>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">To address this, cPanel has created an internal script that parses the PHP.ini file to determine the session path and cleans\/removes any unused PHP session files in the configured directory.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>You&#8217;ll need to run the script below to accomplish this:<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"># \/usr\/local\/cpanel\/scripts\/clean_user_php_sessions<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The script will search for<a href=\"https:\/\/www.php.net\/\" target=\"_blank\" rel=\"noreferrer noopener\"> PHP<\/a> sessions in files named according to the convention below.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">\/sess_.*\/<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You&#8217;ll need to adjust the second parameter. Which is a regex if your web application saves PHP session files in a different format.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Example:<\/strong><\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">\/usr\/local\/cpanel\/scripts\/clean_user_php_sessions 'ci_session\\w+$'<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Do we sincerely hope that you must now have got a clear idea regarding How to Defragment PHP Session Files? However, if you are still facing any difficulty, free to reach out to the <a href=\"https:\/\/www.bodhost.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">bodHOST Team<\/a> for proactive support 24\u00d77.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>What is PHP? PHP is a popular open-source script language that incorporated into HTML and is ideal for Web development. PHP is a server-side scripting language for creating dynamic and&hellip;<\/p>\n<p><a href=\"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":22,"featured_media":6976,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[837],"tags":[901,904,902,903],"class_list":["post-6953","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial","tag-defragment-php-files","tag-php-files","tag-php-session","tag-php-updates"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Defragment PHP Session Files | bodHOST<\/title>\n<meta name=\"description\" content=\"In this article, we are going to understand how to defragment PHP Session files through cPanel. Check out for the latest PHP updates\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Defragment PHP Session Files | bodHOST\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to understand how to defragment PHP Session files through cPanel. Check out for the latest PHP updates\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - bodHOST\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-16T07:01:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T14:03:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-6.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vincer\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-6.png\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vincer\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/\"},\"author\":{\"name\":\"Vincer\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/f3852d74aeac480763235276b5faddd0\"},\"headline\":\"How to Defragment PHP Session Files\",\"datePublished\":\"2021-04-16T07:01:43+00:00\",\"dateModified\":\"2026-02-26T14:03:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/\"},\"wordCount\":231,\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-design-5.png\",\"keywords\":[\"defragment PHP files\",\"PHP files\",\"PHP session\",\"PHP updates\"],\"articleSection\":[\"Tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/\",\"name\":\"How to Defragment PHP Session Files | bodHOST\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-design-5.png\",\"datePublished\":\"2021-04-16T07:01:43+00:00\",\"dateModified\":\"2026-02-26T14:03:09+00:00\",\"description\":\"In this article, we are going to understand how to defragment PHP Session files through cPanel. Check out for the latest PHP updates\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-design-5.png\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-design-5.png\",\"width\":1200,\"height\":628,\"caption\":\"How to Defragment PHP Session Files\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-defragment-php-session-files\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tutorial\",\"item\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/category\\\/tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Defragment PHP Session Files\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"alternateName\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"width\":240,\"height\":240,\"caption\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/f3852d74aeac480763235276b5faddd0\",\"name\":\"Vincer\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bb5079f76e01aaa97b2ffcb7a562292482693b395aba4a4214c98f006c07d352?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bb5079f76e01aaa97b2ffcb7a562292482693b395aba4a4214c98f006c07d352?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/bb5079f76e01aaa97b2ffcb7a562292482693b395aba4a4214c98f006c07d352?s=96&d=mm&r=g\",\"caption\":\"Vincer\"},\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/author\\\/vinayak\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Defragment PHP Session Files | bodHOST","description":"In this article, we are going to understand how to defragment PHP Session files through cPanel. Check out for the latest PHP updates","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/","og_locale":"en_US","og_type":"article","og_title":"How to Defragment PHP Session Files | bodHOST","og_description":"In this article, we are going to understand how to defragment PHP Session files through cPanel. Check out for the latest PHP updates","og_url":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/","og_site_name":"Knowledge Base - bodHOST","article_published_time":"2021-04-16T07:01:43+00:00","article_modified_time":"2026-02-26T14:03:09+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-6.png","type":"image\/png"}],"author":"Vincer","twitter_card":"summary_large_image","twitter_image":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-6.png","twitter_misc":{"Written by":"Vincer","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/#article","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/"},"author":{"name":"Vincer","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/f3852d74aeac480763235276b5faddd0"},"headline":"How to Defragment PHP Session Files","datePublished":"2021-04-16T07:01:43+00:00","dateModified":"2026-02-26T14:03:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/"},"wordCount":231,"publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-5.png","keywords":["defragment PHP files","PHP files","PHP session","PHP updates"],"articleSection":["Tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/","url":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/","name":"How to Defragment PHP Session Files | bodHOST","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/#primaryimage"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-5.png","datePublished":"2021-04-16T07:01:43+00:00","dateModified":"2026-02-26T14:03:09+00:00","description":"In this article, we are going to understand how to defragment PHP Session files through cPanel. Check out for the latest PHP updates","breadcrumb":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/#primaryimage","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-5.png","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2021\/04\/Untitled-design-5.png","width":1200,"height":628,"caption":"How to Defragment PHP Session Files"},{"@type":"BreadcrumbList","@id":"https:\/\/www.bodhost.com\/kb\/how-to-defragment-php-session-files\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Tutorial","item":"https:\/\/www.bodhost.com\/kb\/category\/tutorial\/"},{"@type":"ListItem","position":2,"name":"How to Defragment PHP Session Files"}]},{"@type":"WebSite","@id":"https:\/\/www.bodhost.com\/kb\/#website","url":"https:\/\/www.bodhost.com\/kb\/","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","description":"","publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"alternateName":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bodhost.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bodhost.com\/kb\/#organization","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","url":"https:\/\/www.bodhost.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","width":240,"height":240,"caption":"Web Hosting Knowledge Base | bodHOST Hosting FAQ"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/f3852d74aeac480763235276b5faddd0","name":"Vincer","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/bb5079f76e01aaa97b2ffcb7a562292482693b395aba4a4214c98f006c07d352?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/bb5079f76e01aaa97b2ffcb7a562292482693b395aba4a4214c98f006c07d352?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bb5079f76e01aaa97b2ffcb7a562292482693b395aba4a4214c98f006c07d352?s=96&d=mm&r=g","caption":"Vincer"},"url":"https:\/\/www.bodhost.com\/kb\/author\/vinayak\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/6953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/comments?post=6953"}],"version-history":[{"count":7,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/6953\/revisions"}],"predecessor-version":[{"id":11985,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/6953\/revisions\/11985"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media\/6976"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media?parent=6953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/categories?post=6953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/tags?post=6953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}