Solved

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

Posted on 2010-11-07
4
289 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
  • 2
  • 2
4 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 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 109

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

828 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