Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

13 Experts available now in Live!

Get 1:1 Help Now