[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-11-07
4
Medium Priority
?
294 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

656 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