1

I have several plists set up on my Mac to run several scripts(php) at different intervals over the course of the day. They connect to a website I have (on an external server) and scrape specific information to store in a local database.

All of this worked well until recently when I noticed my database was not getting updated. I placed a few debugging lines of code (write to a text file) inside the scripts that are supposed to be running to see where the error occurs and I think I have narrowed it down to a specific line.

// write to a text file1.txt

$base = "http://www.mywebsite.com/";
$html = file_get_html($base);  // This is the line that causes the script to stop running

// write to a text file2.txt

file1 is written to, but file2 is not written to.

In trying to determine why the script stopped running I looked inside the system.log and noticed this error specifically referring to the plists that should have been launchd

Nov 30 11:43:35 My-iMac com.apple.xpc.launchd[1] (com.whatever.whatever[19088]): Service exited with abnormal code: 255

I unloaded and then loaded all of the plist from terminal:

sudo launchctl unload -w /Library/LaunchDaemons/com.whatever.whatever.plist
sudo launchctl load -w /Library/LaunchDaemons/com.whatever.whatever.plist

I also thought perhaps it was a permissions problem that somehow changed so I:

sudo chown root:wheel /Library/LaunchDaemons/com.nhlrankking.playerstats3.plist

However, they are still not being run completely and get 'stuck' at that same line of code.

If I run the scripts manually, they work fully with no problems or errors.

I'm not sure if it helps, but the Mac is running High Sierra, and I believe the problem occurred roughly around the same time I downloaded the 'Mojave' OS (but I have not yet installed)

I appreciate any help you can give me in solving this problem. I don't have a lot of experience with launchd, and ssh so I'm hoping it's a simple bug, but all searches so far have been fruitless.

----Edit---- Here is the plist file (I know it begins running at the proper time):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.whatever.whatever</string> 
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/php</string>
        <string>/Users/My/Sites/Launchd/my_script.php</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>9</integer>
        <key>Minute</key>
        <integer>30</integer>
    </dict>
</dict>
</plist>
Mason Black
  • 97
  • 2
  • 9
  • Is `file_get_html()` a valid function? Enable error reporting to find out why it's stopping. https://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – miken32 Dec 01 '18 at 03:07
  • Also providing the plist file might be helpful as well. – miken32 Dec 01 '18 at 03:08
  • I should have mentioned that file_get_html() is a function inside the simple_html_dom.php which is listed in the proper directory location => (include "simple_html_dom.php";) I've added the plist file to my question above, but I know this is working properly, because I can tell the script begins to run. – Mason Black Dec 01 '18 at 14:24
  • Ok as long as that’s in the same directory as your script it should be fine though I’d go with `require` instead of `include`. Did you enable logging to a file? – miken32 Dec 01 '18 at 14:33
  • The `require` didn't seem to make a difference. I'm not sure what you mean by 'enable logging to a file'? Currently, the php script is writing to a simple text file (for debugging purposes), however anything after the line file_get_html($base) will no longer be written to the text file, which I'm assuming is because that line stops the entire script from running. – Mason Black Dec 01 '18 at 15:58
  • Check the value of the `error_log` directive with `php -i`. Set it in php.ini if it doesn’t have a value already. – miken32 Dec 01 '18 at 16:01

0 Answers0