?
Solved

How to check if a script is running from Web application (PHP) ?

Posted on 2010-11-07
4
Medium Priority
?
293 Views
Last Modified: 2012-05-10
Here's what I have and what I need to do:

On the server level:

- it's on EC2
- a PHP Web application server where users upload photo entries.
   - there's one flagship Web app server, then there might be other app servers launched by auto-scaling, but all web app belongs to the same load balancer.
- a Mail server, in which I receive photos uploaded from users attached on emails from mobile phones.
- a DB server where photos fetched from emails are inserted temporarily.

On the script side:

- the user can choose from uploading photo either from local PC storage or from her mobile phone.  In this case, we are focusing on the latter case.
- a script that is permanently running on the Web application server fetches for new coming photo-emails from the Mail server (say, with a wait interval of 5 seconds)
- that script gets a list of new coming emails and parse to look for photo data, then inserts the binary data to the DB.
- that script is a command executable PHP script.
- if the mail is fetched and photo data inserted successfully, the user proceeds to the metadata input GUI (i.e. title, comment, etc)

Not so complex, but here's the challenge:
- I want to know and make sure that the fetching script is alive, every time a user sends a new photo-email.

Is there any good way to check if a script is alive on a specific server && if it's dead, re-run it && make sure there won't be several processes running the same process?

What I have in mind right now is to use 'ps -ef | grep SCRIPT_NAME' from PHP to know whether the script is alive, but then I'm not sure about how to let only one script running at the same time, when the re-run process is triggered by different users at the same time.

Sorry if my situation/text is confusing, it must be a weird case for most of us, but I'd appreciate any advice on this PHP-Unix coordination...
0
Comment
Question by:Prochron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 34084147
Hmm... This does not sound like a very good design for a client-server implementation.  Here is what I might do instead...

For the pictures that are emailed, use a mail "pipe" app to receive the email.  Parse the email Subject into the title, and the textual Body into the comment.  Store the binary data not in the DB, but in a manufactured name in a folder of the file system.  Store this file name along with the textual data in the DB.

For the pictures that are sent via a web form, you would have text inputs or textarea fields for the title and comment.  Same storage design - you make up a unique name and use that to connect the DB entry to the image file in the file system.

I could go on and on about why you do not want to put images into a data base, but there are others who have written thoughtfully about this.
http://lmgtfy.com?q=Should+I+store+my+images+in+the+database+or+folders

In this design, each client Email or POST starts the processing, and that is the way client-server environments work.

best of luck with the project, ~Ray
0
 

Author Closing Comment

by:Prochron
ID: 34193910
Ray, thanks for the advice, and sorry for being late.

We implemented with S3/CloudFront for data storage, and it is working fine now.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34196026
Wow, what did I do wrong here?  You marked this down to a "B" without even an opportunity for comment?  I don't understand -- please explain.  Thank you, ~Ray
0
 

Author Comment

by:Prochron
ID: 34280921
hi Ray,
I'm very new to this community, so I apologize if I committed any impoliteness.
What should I do?
I appreciate your guidance.
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question