/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How do I..

How do I check if one PHP script is running within another PHP script.

Lets say “Script A” runs 24/7 pulling live data from a source and I wanted to make a “Script B” that could tell if “Script A” was still running or not.

If it was not running I would then be able to restart “Script A” using “Script B”.

Also..
I there a limit to the amount of PHP scripts that can be running at any given time, and if so where would I find this information?

Thanks,
MrC

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Feb 18.2007 — Command line (CLI)?
Copy linkTweet thisAlerts:
@NightShift58Feb 18.2007 — Not that I know the answer either way...
Copy linkTweet thisAlerts:
@pcthugFeb 18.2007 — You could create a temporary file at the start of [B]script a[/B], and then destroy the temporary file at the end of [B]script a[/B]. The [B]script b[/B] just needs to detect whether the said temporary file exists.
Copy linkTweet thisAlerts:
@NightShift58Feb 18.2007 — You could create a temporary file at the start of [B]script a[/B], and then destroy the temporary file at the end of [B]script a[/B]. The [B]script b[/B] just needs to detect whether the said temporary file exists.[/QUOTE]I don't think you can rely on that. You just need one script to fail, the file will not be deleted and all the other scripts would stumble over it.

You can use the file flagging method, but you must use flock() for that method to be reliable. Of course, all script using that "traffic light" must then adhere to the rule. See an example here:

http://www.webdeveloper.com/forum/showpost.php?p=714889&postcount=5

The reason I asked if he was going to run his scripts from the command line is that, within a Linux environment, there's a way to check on which processes are running and based on that, determine whether to launch the CLI PHP script.
Copy linkTweet thisAlerts:
@MrCoderauthorFeb 19.2007 — Command line (CLI)?[/QUOTE]

Yes mate.
Copy linkTweet thisAlerts:
@NightShift58Feb 19.2007 — If you start the PHP via a shell script, you can check which processes are running - such a shell script being one of them.
×

Success!

Help @MrCoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...