简体   繁体   中英

How to instantiate a PHP object and pass to shell_exec?

I have a PHP process that can take many minutes to complete. From what I have been reading on the web, I believe that the correct way to handle this is that I should use PHP shell_exec() to pass this long running task off to "at" and let the long running task complete. Then once the process is done, write the results to a dbase or file in order to read from the web later on.

However, I need to first get some data from the user via the web in order to continue to on and process the request in the shell script.

Is it possible to instantiate a PHP object via the web session, then pass that object off to the shell_exec() which will run via the "at"? Or does the Apache/PHP architecture not work like that?

If yes, how do you pass a PHP object instantiated in the web session to shell_exec()?

thanks

It depends on the object You want to pass.

If the object contains only pure data, You can serialize it. There is pair of functions in PHP:

  1. https://www.php.net/manual/en/function.serialize.php
  2. https://www.php.net/manual/en/function.unserialize.php

The first one creates a string. You can pass this string to any shell command. The second converts this string back to an object.

Some objects are too complicated and cannot be easily serialized. The PDO is an example of this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM