admin管理员组文章数量:1130349
A WordPress post is supposed to process sample data (uploaded as PDF files) and displays the data (after some manipulations and reformatting) on the same post just below.
...
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="filepdf" />
<input type="submit" name="submit" value="Upload data samples (.pdf file)" />
</form>
...
I use the PHP code snippets (Insert PHP) plugin to include PHP code.
...
[insert_php]
if(isset($_FILES['filepdf'])) {
$mTime = number_format(microtime(true), 3, '.', '');
$file_name = $_FILES['filepdf']['name'];
$file_size = $_FILES['filepdf']['size'];
$file_tmp = $_FILES['filepdf']['tmp_name'];
$file_ext = strtolower(end(explode('.', $_FILES['filepdf']['name'])));
...
$cmd = "./mybinary '$file_name'";
$outfile = tempnam("/tmp", "cmd");
$errfile = tempnam("/tmp", "cmd");
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", $outfile, "w"),
2 => array("file", $errfile, "w")
);
move_uploaded_file($file_tmp, $file_name);
$proc = proc_open($cmd, $descriptorspec, $pipes);
...
[/insert_php]
Hours of troubleshooting, but I don't find why this happens ... when I upload a PDF file, the binary mybinary in proc_open() fires twice - sometimes (spaced by +/- 200 ms). Let's say 95% of all requests work fine, but 5% fail due to these double triggers. It seems (?!) that mobile Android devices using Chrome are more affected than other operating systems and/or browsers (not sure at all about that though). This is at least what Apache's access.log says. The present situation is unacceptable since the binary uses millisecond timecode generated by the PHP code (see above), and this messes up the entire process.
Questions:
1. Is my assumption correct that Chrome sends two requests?
2. If yes, why?
3. How can I avoid that?
I googled about that, and indeed, it seems that proc_open() sometimes fires twice, but I didn't find any solution.
Also, I don't know if this is WordPress related, or a PHP subject.
A WordPress post is supposed to process sample data (uploaded as PDF files) and displays the data (after some manipulations and reformatting) on the same post just below.
...
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="filepdf" />
<input type="submit" name="submit" value="Upload data samples (.pdf file)" />
</form>
...
I use the PHP code snippets (Insert PHP) plugin to include PHP code.
...
[insert_php]
if(isset($_FILES['filepdf'])) {
$mTime = number_format(microtime(true), 3, '.', '');
$file_name = $_FILES['filepdf']['name'];
$file_size = $_FILES['filepdf']['size'];
$file_tmp = $_FILES['filepdf']['tmp_name'];
$file_ext = strtolower(end(explode('.', $_FILES['filepdf']['name'])));
...
$cmd = "./mybinary '$file_name'";
$outfile = tempnam("/tmp", "cmd");
$errfile = tempnam("/tmp", "cmd");
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", $outfile, "w"),
2 => array("file", $errfile, "w")
);
move_uploaded_file($file_tmp, $file_name);
$proc = proc_open($cmd, $descriptorspec, $pipes);
...
[/insert_php]
Hours of troubleshooting, but I don't find why this happens ... when I upload a PDF file, the binary mybinary in proc_open() fires twice - sometimes (spaced by +/- 200 ms). Let's say 95% of all requests work fine, but 5% fail due to these double triggers. It seems (?!) that mobile Android devices using Chrome are more affected than other operating systems and/or browsers (not sure at all about that though). This is at least what Apache's access.log says. The present situation is unacceptable since the binary uses millisecond timecode generated by the PHP code (see above), and this messes up the entire process.
Questions:
1. Is my assumption correct that Chrome sends two requests?
2. If yes, why?
3. How can I avoid that?
I googled about that, and indeed, it seems that proc_open() sometimes fires twice, but I didn't find any solution.
Also, I don't know if this is WordPress related, or a PHP subject.
Share Improve this question edited Nov 7, 2018 at 6:59 geohei asked Oct 23, 2018 at 15:09 geoheigeohei 1112 bronze badges 5 |1 Answer
Reset to default 1To complete this ... I initially used PHP code snippets (Insert PHP) plugin (version 2.0.6 - latest). The php page was in fact only called once, but executed twice. I didn't have any explanation for all this described above (same temp filename, but code called twice, ...).
After I changed the PHP code WordPress integration method into the Shortcode concept, all worked fine (till now). So I believe that this mentioned plugin was the reason for the double triggers?!
And no double clicks - I checked that already right from the beginning. So probably the PHP code itself was not the culprit.
A WordPress post is supposed to process sample data (uploaded as PDF files) and displays the data (after some manipulations and reformatting) on the same post just below.
...
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="filepdf" />
<input type="submit" name="submit" value="Upload data samples (.pdf file)" />
</form>
...
I use the PHP code snippets (Insert PHP) plugin to include PHP code.
...
[insert_php]
if(isset($_FILES['filepdf'])) {
$mTime = number_format(microtime(true), 3, '.', '');
$file_name = $_FILES['filepdf']['name'];
$file_size = $_FILES['filepdf']['size'];
$file_tmp = $_FILES['filepdf']['tmp_name'];
$file_ext = strtolower(end(explode('.', $_FILES['filepdf']['name'])));
...
$cmd = "./mybinary '$file_name'";
$outfile = tempnam("/tmp", "cmd");
$errfile = tempnam("/tmp", "cmd");
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", $outfile, "w"),
2 => array("file", $errfile, "w")
);
move_uploaded_file($file_tmp, $file_name);
$proc = proc_open($cmd, $descriptorspec, $pipes);
...
[/insert_php]
Hours of troubleshooting, but I don't find why this happens ... when I upload a PDF file, the binary mybinary in proc_open() fires twice - sometimes (spaced by +/- 200 ms). Let's say 95% of all requests work fine, but 5% fail due to these double triggers. It seems (?!) that mobile Android devices using Chrome are more affected than other operating systems and/or browsers (not sure at all about that though). This is at least what Apache's access.log says. The present situation is unacceptable since the binary uses millisecond timecode generated by the PHP code (see above), and this messes up the entire process.
Questions:
1. Is my assumption correct that Chrome sends two requests?
2. If yes, why?
3. How can I avoid that?
I googled about that, and indeed, it seems that proc_open() sometimes fires twice, but I didn't find any solution.
Also, I don't know if this is WordPress related, or a PHP subject.
A WordPress post is supposed to process sample data (uploaded as PDF files) and displays the data (after some manipulations and reformatting) on the same post just below.
...
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="filepdf" />
<input type="submit" name="submit" value="Upload data samples (.pdf file)" />
</form>
...
I use the PHP code snippets (Insert PHP) plugin to include PHP code.
...
[insert_php]
if(isset($_FILES['filepdf'])) {
$mTime = number_format(microtime(true), 3, '.', '');
$file_name = $_FILES['filepdf']['name'];
$file_size = $_FILES['filepdf']['size'];
$file_tmp = $_FILES['filepdf']['tmp_name'];
$file_ext = strtolower(end(explode('.', $_FILES['filepdf']['name'])));
...
$cmd = "./mybinary '$file_name'";
$outfile = tempnam("/tmp", "cmd");
$errfile = tempnam("/tmp", "cmd");
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("file", $outfile, "w"),
2 => array("file", $errfile, "w")
);
move_uploaded_file($file_tmp, $file_name);
$proc = proc_open($cmd, $descriptorspec, $pipes);
...
[/insert_php]
Hours of troubleshooting, but I don't find why this happens ... when I upload a PDF file, the binary mybinary in proc_open() fires twice - sometimes (spaced by +/- 200 ms). Let's say 95% of all requests work fine, but 5% fail due to these double triggers. It seems (?!) that mobile Android devices using Chrome are more affected than other operating systems and/or browsers (not sure at all about that though). This is at least what Apache's access.log says. The present situation is unacceptable since the binary uses millisecond timecode generated by the PHP code (see above), and this messes up the entire process.
Questions:
1. Is my assumption correct that Chrome sends two requests?
2. If yes, why?
3. How can I avoid that?
I googled about that, and indeed, it seems that proc_open() sometimes fires twice, but I didn't find any solution.
Also, I don't know if this is WordPress related, or a PHP subject.
Share Improve this question edited Nov 7, 2018 at 6:59 geohei asked Oct 23, 2018 at 15:09 geoheigeohei 1112 bronze badges 5-
1
This will execute however many times the content is parsed, but keep in mind, the
[insert_php]shortcode you're using is incredibly dangerous, it's one of the most dangerous things you can do to a site. Instead just implement a shortcode and put the PHP code inside an actual PHP file. Again, I cannot understate just how dangerous what you're doing is, and how stupendously dangerous plugins that let you do this are. – Tom J Nowell ♦ Commented Oct 23, 2018 at 15:32 -
Thanks for the comment! I try to get rid of
[insert_php]then. I was completely unaware of that risk (WP newbie in PHP coding). Never wrote my own shortcode. Do I need a plugin to write/use my own shortcode? Is this a good site to get started? link. If not, please give me a starting point. Thanks! – geohei Commented Oct 23, 2018 at 19:52 - No, you can create a plugin to do the shortcode, but a plugin is just a PHP file with a comment at the top in the plugins folder. A shortcode shouldn't be very difficult to write, especially if you already have PHP code written – Tom J Nowell ♦ Commented Oct 23, 2018 at 19:52
- @TomJNowell - I don't really understand what is so dangerous in this PHP plugin, but since the code was not working properly, I gave the Shortcode concept a try. See below ... – geohei Commented Nov 6, 2018 at 7:58
-
The problem is that anybody who can use shortcodes or write to the database can execute PHP, no filesystem access required. In combination with other shortcode features, somebody could sneak in an
insert_phpshortcode and execute anything on the server – Tom J Nowell ♦ Commented Nov 6, 2018 at 20:35
1 Answer
Reset to default 1To complete this ... I initially used PHP code snippets (Insert PHP) plugin (version 2.0.6 - latest). The php page was in fact only called once, but executed twice. I didn't have any explanation for all this described above (same temp filename, but code called twice, ...).
After I changed the PHP code WordPress integration method into the Shortcode concept, all worked fine (till now). So I believe that this mentioned plugin was the reason for the double triggers?!
And no double clicks - I checked that already right from the beginning. So probably the PHP code itself was not the culprit.
本文标签: phpprocopen() fires twice
版权声明:本文标题:php - proc_open() fires twice 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749201130a2331819.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


[insert_php]shortcode you're using is incredibly dangerous, it's one of the most dangerous things you can do to a site. Instead just implement a shortcode and put the PHP code inside an actual PHP file. Again, I cannot understate just how dangerous what you're doing is, and how stupendously dangerous plugins that let you do this are. – Tom J Nowell ♦ Commented Oct 23, 2018 at 15:32[insert_php]then. I was completely unaware of that risk (WP newbie in PHP coding). Never wrote my own shortcode. Do I need a plugin to write/use my own shortcode? Is this a good site to get started? link. If not, please give me a starting point. Thanks! – geohei Commented Oct 23, 2018 at 19:52insert_phpshortcode and execute anything on the server – Tom J Nowell ♦ Commented Nov 6, 2018 at 20:35