title: Is it better to run Cron every minute or write Cron Job dynamically?
body: <p>I have a simple application where users can add a post and schedule it to go live at a certain time. </p>
  
  <p>Now I have two approaches before me: </p>
  
  <p><strong>First Approach:</strong> 
  I can set a script which will be called every minute and it will check if any posts are pending at the current time and will publish them if they are like so: </p>
  
  <p>My Cron Job:</p>
  
  <pre><code>1 * * * * php myScriptToMakePostLive.php
  </code></pre>
  
  <p>or </p>
  
  <p><strong>Second Approach</strong>
  I can set cron jobs dynamically on server at the time when user submits his post to publish later. I am using this script: </p>
  
  <pre><code> public function schedulePost(){
          $post = new Post();
          $post-&gt;body = $_POST['body'];
          $post-&gt;save();
  
          $scheduledTime = Carbon::parse($_POST['publish_on']);
  
          //saving cron dynamically 
          $output = shell_exec('crontab -l');
          file_put_contents('/tmp/crontab.txt', $output.PHP_EOL."{$scheduledTime-&gt;minute} {$scheduledTime-&gt;hour} {$scheduledTime-&gt;day} {$scheduledTime-&gt;month} * php myScriptToMakePostLive {$post-&gt;id}".PHP_EOL);
          echo exec('crontab /tmp/crontab.txt');
          die('Your post has been Scheduled !!');
  
      } 
  </code></pre>
  
  <p>What I want to know is which is the better approach and why? </p>