Karaethon Posted March 26, 2019 Share Posted March 26, 2019 I know that cron can run a script automatically at scheduled intervals but I have no knowledge of how to set this up. Both the cron AND the script. I can learn, obviously, but I have a question before diving in. Can I trigger an unsceduled run of the script from another script? Specifically, I have in mysql a database of number puzzles, the script will check the number of unsolved and generate new ones as needed to keep the number near the planned 1000 point. but if there is a surge of solves I want other script (user interacting script) to trigger the other script if the number drops to 100 or less. I don't want the user script hanging while puzzles are generated so i need to trigger the housekeeper script outside the userscript thread. Quote Link to comment Share on other sites More sharing options...
chhorn Posted March 26, 2019 Share Posted March 26, 2019 (edited) If you read the documentation you will find out that cron jobs are basically just scheduled CLI calls. So if you can run that script via cron you can mostly run it via CLI at any time (at least you should test this anyway). At worst an include 'filename.php' will run that script. Edited March 26, 2019 by chhorn Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted March 26, 2019 Share Posted March 26, 2019 Yes you could have a script initiate another script, but you also have another potential solution not to use a cron but have your confirmedSolved() method trigger the creation of a new puzzle. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 26, 2019 Share Posted March 26, 2019 First of all - who is your host? You? Or do you pay for some shared hosting? With the latter the cron question is usually solved since most providers include cron abilities in their package to you. With their (cpanel?) screen you name the script to be run and setup how often you want it to run. Within your script - a php script - you have to place a simple hashbang(?) line (which your host will define for you) at the top to allow the cron job to run it and then design your script to run without any console/client output. It runs in the background but has full access to your db and the php toolset so that you can do anything you want. Therefore you could just schedule it to run hourly (?) and have it check the results in your db and from that do whatever it takes to produce more puzzles or whatever you want. Hope this helps. Quote Link to comment Share on other sites More sharing options...
Karaethon Posted March 26, 2019 Author Share Posted March 26, 2019 Hmm, ok.... Thanks I have never used cron before except what the host or premade site used, I don't know how to make my own. But NotionCommotion pointed out something I was too close to see... Everytime a puzzle is solved run the generator. facepalm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.