LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2011, 06:54 AM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 924

Rep: Reputation: 61
Question Use PHP to read cron launched php scripts?


Hey guys,

I have a php script that runs at regular intervals on my LAMP machine. It mostly just checks scores of sports games and such and then emails them to my phone for when I'm away from the games. I was mostly just curious if there was a way to report (possibly using AJAX and php) to check to see when the script is currently running.

What I currently have set up is a field in an sql table that says whether or not the script has been launched or not. In the beginning of the script it marks the changes the 'active' field to 1. At the end of the script it sets the active field to 0. The problem I am having with this is that if the script ever fails during it's run, it never marks the script as un-active.

So what I'm hoping I can do is check at the linux level whether or not the process is running.

Is there any way to do that with PHP (it happens to be the language I'm familiar with)?

I know PHP has a system() function that allows the programmer to run actual calls from the command line and then maybe it's possible to parse the output?

Maybe something like "system('ps aux | grep 'php pathtophp/script.php?id=soccer')" ?

Any ideas or tips in the right direction are fully appreciated!
 
Old 04-22-2011, 07:54 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
ps would work.
or maybe save the PID of the script and run kill -0 on it.
 
Old 04-22-2011, 06:32 PM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 924

Original Poster
Rep: Reputation: 61
What does kill -0 do on it?

Would my command be "ps | grep pid xx kill -0"?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
mplayer launched from apache-php plays, but no sound... lumix Linux - Hardware 4 05-02-2008 09:50 AM
php5 apache2 mysql4 don't work, php does not seem to read php.ini atom Linux - Software 5 03-24-2005 11:05 AM
Upgraded PHP from 4.3.4 to 4.3.10 and now it won't read php.ini gregmcavoy Linux - Software 11 01-22-2005 12:16 PM
PHP unable to read .php files tuka Linux - Software 6 10-12-2003 06:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration