{"id":5377,"date":"2019-05-13T12:11:35","date_gmt":"2019-05-13T12:11:35","guid":{"rendered":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?p=5377"},"modified":"2022-02-19T10:41:05","modified_gmt":"2022-02-19T10:41:05","slug":"learn-to-run-php-scripts-from-cron-jobs","status":"publish","type":"post","link":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/","title":{"rendered":"Learn to run PHP Scripts from Cron jobs"},"content":{"rendered":"<p>Cron is a utility that allows you to schedule your task so that later it can be run automatically. It is basically a program that runs at the back of the process and can be scheduled (time-based) through commands or cPanel on web hosts. These commands are nothing but the jobs or tasks that are called &#8220;Cron Jobs&#8221;. Cron is also available with the Unix-like operating systems such as Linux, Mac, FreeBSD, etc.<\/p>\n<h2>Running PHP scripts from Cron jobs.<\/h2>\n<p>Running PHP scripts from a cron job using a command-line program such as curl or wget is a common way.<br \/>\nFor example : a cron job runs a command like<\/p>\n<p><strong>curl http:\/\/example.com\/script.php<\/strong><\/p>\n<p>where, curl accesses the web page, which then runs the PHP script.<\/p>\n<p>However, you can also run the script directly by using the PHP command-line interpreter. This is also an effective and faster method to run PHP scripts on our website from cron jobs.<\/p>\n<p><strong>Related: <a href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/add-edit-delete-cron-jobs-cpanel\/\" target=\"_blank\" rel=\"noopener\">How to Add, Edit and Delete Cron Jobs in cPanel<\/a><\/strong><\/p>\n<p>Let&#8217;s see a command that shows how to run a script using the PHP command-line interpreter :<\/p>\n<p><strong>php -q \/home\/username\/public_html\/script.php<\/strong><\/p>\n<p>In this above example, the PHP command-line interpreter runs the script.php file.<br \/>\nThe -q option is responsible to enable quiet mode which prevents HTTP headers from being displayed.<\/p>\n<p>Your PHP script can run correctly only when it is called from a specific directory that depends on the code in your PHP script.<br \/>\nFor example, if the script has to use relative paths to include files, then it will only run when it is called from the correct directory. A command for how to call a PHP script from a specific directory is :<\/p>\n<p><strong>cd \/home\/username\/public_html\/; php -q script.php<\/strong><\/p>\n<p>For the special configuration options in your script, you can use a custom php.ini.file like the example shown below :<\/p>\n<p><strong>php -c \/home\/username\/php.ini \/home\/username\/public_html\/script.php<\/strong><\/p>\n<p>Here, <strong>-c<\/strong> option allows you to call a <strong>PHP script<\/strong> using a custom php.ini file.<\/p>\n<p>This is all about how you can PHP script from cron jobs.<\/p>\n<p><strong>Also Read :<\/strong><\/p>\n<p><strong>1)\u00a0<\/strong><a href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/how-to-take-the-cron-job-backups-using-jetbackup\/\" target=\"_blank\" rel=\"noopener\"><strong>How to Take the Cron Job Backups using JetBackup?<\/strong><\/a><\/p>\n<p><strong>2)\u00a0<\/strong><a href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/cron-jobs-cpanel\/\" target=\"_blank\" rel=\"noopener\"><strong>Cron jobs (cPanel)<\/strong><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cron is a utility that allows you to schedule your task so that later it can be run automatically. It is basically a program that runs at the back of the process and can be scheduled (time-based) through commands or cPanel on web hosts. These commands are nothing but the jobs or tasks that are [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":5379,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[658,18,659],"class_list":["post-5377","post","type-post","status-publish","format-standard","has-post-thumbnail","placeholder-for-hentry","category-howtos","tag-cron-jobs","tag-php","tag-php-script"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learn to run PHP Scripts from Cron jobs - Web Hosting FAQs by MilesWeb<\/title>\n<meta name=\"description\" content=\"PHP scripts can be run from cron jobs. Learn the easy way of doing so with this step by step guide. It will explain you easy commands to perform your work.\" \/>\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.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn to run PHP Scripts from Cron jobs - Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"og:description\" content=\"PHP scripts can be run from cron jobs. Learn the easy way of doing so with this step by step guide. It will explain you easy commands to perform your work.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-13T12:11:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-19T10:41:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"445\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Sonam Wagh\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sonam Wagh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/\",\"name\":\"Learn to run PHP Scripts from Cron jobs - Web Hosting FAQs by MilesWeb\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png\",\"datePublished\":\"2019-05-13T12:11:35+00:00\",\"dateModified\":\"2022-02-19T10:41:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/dc645d02823c86e07e53798ebe02c6f4\"},\"description\":\"PHP scripts can be run from cron jobs. Learn the easy way of doing so with this step by step guide. It will explain you easy commands to perform your work.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#primaryimage\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png\",\"contentUrl\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png\",\"width\":800,\"height\":445,\"caption\":\"PHP script from Cron jobs\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learn to run PHP Scripts from Cron jobs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/dc645d02823c86e07e53798ebe02c6f4\",\"name\":\"Sonam Wagh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9cb2cf6ae11d7625ef6417ef8e84ba25?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9cb2cf6ae11d7625ef6417ef8e84ba25?s=96&d=blank&r=g\",\"caption\":\"Sonam Wagh\"},\"description\":\"With an interest in doing something creative daily, Sonam works as a Digital Marketing Executive. She likes to write technical blogs related to web hosting, digital marketing, and other IT topics. She also likes to spend her leisure time on social media to find different strategies for client engagement.\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/sonam\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn to run PHP Scripts from Cron jobs - Web Hosting FAQs by MilesWeb","description":"PHP scripts can be run from cron jobs. Learn the easy way of doing so with this step by step guide. It will explain you easy commands to perform your work.","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.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/","og_locale":"en_GB","og_type":"article","og_title":"Learn to run PHP Scripts from Cron jobs - Web Hosting FAQs by MilesWeb","og_description":"PHP scripts can be run from cron jobs. Learn the easy way of doing so with this step by step guide. It will explain you easy commands to perform your work.","og_url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2019-05-13T12:11:35+00:00","article_modified_time":"2022-02-19T10:41:05+00:00","og_image":[{"width":800,"height":445,"url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png","type":"image\/png"}],"author":"Sonam Wagh","twitter_misc":{"Written by":"Sonam Wagh","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/","name":"Learn to run PHP Scripts from Cron jobs - Web Hosting FAQs by MilesWeb","isPartOf":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#primaryimage"},"image":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#primaryimage"},"thumbnailUrl":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png","datePublished":"2019-05-13T12:11:35+00:00","dateModified":"2022-02-19T10:41:05+00:00","author":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/dc645d02823c86e07e53798ebe02c6f4"},"description":"PHP scripts can be run from cron jobs. Learn the easy way of doing so with this step by step guide. It will explain you easy commands to perform your work.","breadcrumb":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#primaryimage","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png","contentUrl":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/05\/Learn-to-run-PHP-Scripts-from-Cron-jobs-min.png","width":800,"height":445,"caption":"PHP script from Cron jobs"},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/learn-to-run-php-scripts-from-cron-jobs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"Learn to run PHP Scripts from Cron jobs"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/dc645d02823c86e07e53798ebe02c6f4","name":"Sonam Wagh","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9cb2cf6ae11d7625ef6417ef8e84ba25?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9cb2cf6ae11d7625ef6417ef8e84ba25?s=96&d=blank&r=g","caption":"Sonam Wagh"},"description":"With an interest in doing something creative daily, Sonam works as a Digital Marketing Executive. She likes to write technical blogs related to web hosting, digital marketing, and other IT topics. She also likes to spend her leisure time on social media to find different strategies for client engagement.","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/sonam\/"}]}},"views":1581,"_links":{"self":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/5377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=5377"}],"version-history":[{"count":3,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/5377\/revisions"}],"predecessor-version":[{"id":13831,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/5377\/revisions\/13831"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media\/5379"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=5377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=5377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=5377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}