Solved

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

Posted on 2010-11-07
4
286 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 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access_log 17 97
Parts and Products table schema in mysql 6 43
WordPress Themes 10 34
Linux VM 6 17
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

932 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now