Executing php shell command gives random exit only in heavy use mode

Please help me with this problem I am facing on a production server. I ran an application that only saves images to a directory after verifying that it doesn't already exist.

To check if it exists I used the following command find $filePath -name $fileInitial*

I am very surprised to see that everything went well for development and QA, but in a real environment, out of 50 cases, in 5 cases it returns empty even if the file exists.

I tried to replace the backtick operator exec

, shell_exec

, passthru

and system

. I even tried to replace the command find

with ls

, but it didn't get any gain.

Please suggest what can be done?


source to share

3 answers

Depending on your code, I would highly recommend avoiding exec / shell_exec as much as possible.

This poses a very large security risk to your entire system if not coded with security in mind.

Not sure why you are having trouble with the actual command you are trying to process, however my suggestion would be to use file_exists () or glob () works in php rather than manually on the filesystem.



Thanks everyone. Your suggestions really worked. Everything worked well with glob ().

Maybe the reason is that executing a shell command through php doesn't wait enough time for the result. Or it has something to do with the CGI mode where php is running.

Share your thoughts.



Have you established: ignore_user_abort(true);

and set_time_limit()

to something reasonable? Try also with popen (). I always find it easier for the right interface.



All Articles