title: Split up a large cron job into multiple cron jobs?
body: <p>I'm using Laravel 5.2. I currently have a cron job where it fetches many thousands of rows from my database and performs computations on each of those rows. The cron job currently takes roughly an hour to run, but the database continues to get larger every day.</p>
  
  <p>One option would be to manually add more cron jobs using <code>crontab -e</code> (i.e. 5 cron jobs that split the job into 5 smaller parts). However, is it also possible to do something like the following:</p>
  
  <ol>
  <li>Set up a single cron job using <code>crontab -e</code>.</li>
  <li>The cron job script gets all the rows from the database and, depending on how many rows are returned, it determines how many cron jobs it should further be split into. For example, if the database returns 1000 rows, it should split it into 10 cron jobs, but if the database returns 10000 rows, it should split it into 100 cron jobs.</li>
  </ol>
  
  <p>So my question is, is it possible to have only a single cron job listed in <code>crontab -e</code>, where the PHP script then decides how many more cron jobs it should be split into (essentially calling more cron jobs from a PHP script)?</p>
  
  <p>Is it safe to do this? Is there a better way to approach this?</p>
  
  <p>Here is my current script:</p>
  
  <pre><code>class PostCron extends Command
  {
      /**
       * The name and signature of the console command.
       *
       * @var string
       */
      protected $signature = 'post_cron';
  
      /**
       * The console command description.
       *
       * @var string
       */
      protected $description = '';
  
      /**
       * Execute the console command.
       *
       * @return mixed
       */
      public function handle()
      {
          $posts = Post::all(); // currently returns ~1000 rows, but grows in size daily
  
          foreach ($posts as $post) {
              // computations on each separate post
          }
      }
  }
  </code></pre>