Jump to content

NotionCommotion

Members
  • Posts

    2,446
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by NotionCommotion

  1. After a React loop addPeriodicTimer timer is started, how do I change it? For instance, how can I change interval1 timer within the socket on data callback? Thanks <?php require 'vendor/autoload.php'; use React\EventLoop\Factory; use React\Socket\Connection; $interval1=20; $interval2=50; $loop = Factory::create(); $app = new \ClientApp; $server = @stream_socket_client("tcp://123.421.23.41:123", $errno, $errstr, STREAM_CLIENT_ASYNC_CONNECT); $socket = new Connection($server, $loop); $socket->on('data', function($data) use ($app) { //Change $interval1 }); $loop->addPeriodicTimer($interval1, function() use ($app) { $app->do_something(); }); $loop->addPeriodicTimer($interval2, function() use ($app) { $app->some_other_non_related_loop(); //Just shown so that you know there is more than one loop happening, so one must be able to somehow select the correct one when changing the timer });
  2. Hi benanamen, Have you had any success with setting up node.js per How to Manage Your CSS and JS ? Doesn't work for me, and npm install results in the following error: npm ERR! Error: No compatible version found: webpack@'>=2.1.0-beta.15 <=2.1.0--beta.22'
  3. Turns out Route::group(['middleware' => ['web']], function() {}) and Route::group(['middleware' => web'], function() {}) are the same, and if more than one middleware are desired, one should use an array and pass both. I expect that $middlewareGroups and $routeMiddleware are both searched and added as applicable. Yea, Laravel does all the work and authorization is easy, however, it still seems a little magical to me. I found it helpful to git the directory so I can see what files Laravel is changing when I do things such as php artisan make:auth.
  4. Thanks again benanamen, Still a little confused. Per https://laravel.com/docs/5.3/routing, I see two routes both which utilize the auth middleware. Route::group(['middleware' => 'auth'], function () { Route::get('/', function () { // Uses Auth Middleware }); Route::get('user/profile', function () { // Uses Auth Middleware }); }); I would like to compare this against the following. Route::group(['middleware' => ['web']], function() { Route::resource('blog','BlogController'); }); Because, middleware is set to an array ['web'] and not a string, all the following middleware is added to the route? What if I also wanted the 'auth' middleware? 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ] And then I don't see individual routes, but understand that Route::resource() https://laravel.com/docs/5.3/controllers#resource-controllers makes 7 routes to the seven methods (index, create, store, show, edit, update,destroy) in BlogController for the particular http method. Do I understand this correctly?
  5. Have fun on emails! Can you explain the following lines of code to me? Route::group(['middleware' => ['web']], function() { Route::resource('blog','BlogController'); });
  6. Hi Benanamen, Did you get the following error? "NetworkError: 404 Not Found - http://laravel.example.com/css/font-awesome.min.css"
  7. https://laravel.com/docs/5.1/quickstart ships with 5.2.20. Note sure how much different it will be from 5.3.24. [Michael@devserver laravel]$ php artisan --version Laravel Framework version 5.3.24 [Michael@devserver laravel]$ cd .. [Michael@devserver www]$ cd qu* [Michael@devserver quickstart]$ php artisan --version Laravel Framework version 5.2.20 [Michael@devserver quickstart]$
  8. I've never used a 3rd party framework, and am thinking of trying one out. Any recommendations on which one to try first? What about Laravel? Playing with it, and my initial concern is that it seems a little mystic regarding configuration. Any recommended Laravel tutorials? I am using https://laravel.com/docs/5.1/quickstart, and the database won't connect. Looking at .env, I see the database credentials are not correct, and I suppose I set them here, but am concerned that this tutorial doesn't even address doing so.
  9. I'm using Composer version 1.2.0. Even https://laravel.com/docs/5.1/quickstart shows it as composer create-project laravel/laravel quickstart --prefer-dist, however, since the directory is also given, it doesn't attempt to use the option as the directory path. Oh well, all is good. Thank you kicken for your reply.
  10. Are you sure you are really including include/SessionManage.php')? Prove it to yourself, and add at the very top exit('testing');
  11. Trying to install laravel, and was following a tutorial at https://www.tutorialspoint.com/laravel/laravel_installation.htm. Why is --prefer-dist directory not being recognized as a flag, but is being used fort he target directory? https://getcomposer.org/doc/03-cli.md#create-project shows doing something similar with php composer.phar create-project doctrine/orm path 2.2.*. composer create-project --prefer-dist laravel/laravel blog described by https://laravel.com/docs/5.3 will install it in ./blog. [Michael@devserver testl]$ pwd /var/www/testl [Michael@devserver testl]$ ls -la total 8 drwxrwxr-x. 2 Michael Michael 4096 Nov 22 07:21 . drwxrwxr-x. 28 root root 4096 Nov 22 07:21 .. [Michael@devserver testl]$ composer create-project laravel/laravel –-prefer-dist Installing laravel/laravel (v5.3.16) - Installing laravel/laravel (v5.3.16) Loading from cache Created project in –-prefer-dist > php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies (including require-dev) - Installing vlucas/phpdotenv (v2.4.0) etc, etc, etc.... Loading from cache symfony/var-dumper suggests installing ext-symfony_debug () phpunit/phpunit suggests installing phpunit/php-invoker (~1.1) phpunit/phpunit suggests installing ext-xdebug (*) Writing lock file Generating autoload files > Illuminate\Foundation\ComposerScripts::postUpdate > php artisan optimize Generating optimized class loader The compiled class file has been removed. > php artisan key:generate Application key [base64:g+JF6MyWuEynyoyh//Afo1xg/2RiZSn5tF3cf1mQZp0=] set successfully. [Michael@devserver testl]$ ls -la total 12 drwxrwxr-x. 3 Michael Michael 4096 Nov 22 07:22 . drwxrwxr-x. 28 root root 4096 Nov 22 07:21 .. drwxrwxr-x. 12 Michael Michael 4096 Nov 22 07:22 –-prefer-dist [Michael@devserver testl]$
  12. The only reason I said 60/30 is I am going through a transition period where I wish to return objects as I feel they are more readable instead of associated arrays which I did in the past, and I actually feel it should be 91% objects, 4% associated arrays, and 5% columns for me (more or less ). And if my new default is an object, there are some times when an array is more applicable such as when I wish to perform some array difference function and don't wish to have to take the extra step to convert the DB result from an object to an array.
  13. My rational for the Commands class was to ensure that only applicable methods exist in it, and it would have no internal methods. If I really needed an internal method, I can make it not public and add to my method_exists() check whether the supplied command is public. In hindsight, I guess that won't work as I have my constructor method to deal with. Given the following script as a starting point, please elaborate on your statement "you should always call the same fixed(!) method which then maps $cmd to some action, using a closure or an actual method after checking a whitelist." Thank you <?php $otherStuff=(object)['a'=>1,'b'=>2,'c'=>3]; $client = new \Client(new \Commands($otherStuff), $otherStuff); $client->start(); class Client { private $commands, $otherStuff; public function __construct($commands, $otherStuff) { $this->commands = $commands; $this->otherStuff = $otherStuff; } public function socketsCallBack($cmd,$data) { $map=['doA'=>'doAFunction','doB'=>'doBFunction','doC'=>'doCFunction']; if(isset($map[$cmd])) { $this->commands->{$map[$cmd]}($data); } } } class Commands { private $otherStuff; public function __construct($otherStuff) { $this->otherStuff = $otherStuff; } public function doAFunction($data){} public function doBFunction($data){} public function doCFunction($data){} }
  14. Without posting a bunch of script, hopefully the following will describe my dilemma. I have the following script. $client = new \Client($db, new \Commands($logger), $logger); $client->start(); Client's constructor will store Commands as $this->commands and will also poll the DB and save the results in another property $this->otherStuff. Client also has a callback to a sockets connection, and given $cmd and $data, will perform if(method_exists($this->commands,$cmd)) { $this->commands->{$cmd}($data); }. Now, my difficulty. Some of the methods in Commands needs access to Client's $this->otherStuff. As I see it, I have the following options. Move Command's methods to Client. Commands perform specific tasks, and this doesn't seem the right thing to do. Create the Command's object within Client's constructor. This seems to go against dependency injection. Get otherStuff outside of Client, and pass it to both Client and Command. Something else? Hopefully this is enough information for some "general" recommendations. Thank you
  15. Yes, Jessica might not have formatted her existing script correctly for this forum, but her questions were not bad. And yes, her professor might be at fault for teaching obsolete techniques, but that is not her fault. She never said that she wanted to fake herself as a programmer, and in fact said she didn't want to become one. What is wrong with trying to expand ones horizon by becoming familiarl with programming, and maybe she will become one (and I hope a good one!) if we support her and get off her case. I have a 13 year old daughter who shows interest, and I am as passionate as Jacques1 is about security that we support young ladies in this industry.
  16. Ah... I just assumed authentication was in place. White listing would also be a good idea. Remind me not to give a user account to the OP!
  17. Is Net_SSH2, running cl commands on Nucleus's server where his/her PHP is running, or some remote server? It was my understanding that some remote server. If I have username/password of one of those remote servers, I can ssh and issue the commands via putty, etc. Isn't using PHP to do so just automating the process? What is the difference?
  18. JessicaC, I think Jacques1 is being a little harsh, but as you can tell, he is a bit passionate, and I believe his intentions are good. I recognize you have multiple objects: make the code work, pass the class, be efficient, and do it right. The key is to keep on going and have fun, and the rest will follow.
  19. Often, the desired format of the results depends on what one is doing with the results. I probably return objects 60% of the time, associated arrays 30% of the time, and a single column 10% of the time. Currently, I explicitly state the desired format every time. I believe a benefit of doing so is the intent is smack in front of me. It seems an advantage of globally setting in the PDO constructor is less typing. Are there performance advantages or other advantages of setting in the constructor?
  20. @Nucleus I borrowed this code from someone years ago. Purpose was not the same, but similar. Used it for a while, but then changed tacks, and I can't really vouch for it. @Jacques1 Why is it dangerous? I know nothing about Net_SSH2, but assume it is an abstraction layer to allow PHP to logon via SSH and issue command line commands. Presumably, the remote machine will not allow them to run should the agent not be authenticated, and will only allow commands for that users permissions. function closeConnection($body, $responseCode=200, $timeout=0){ // If zero, no timeout set_time_limit($timeout); // Client disconnect should NOT abort our script execution ignore_user_abort(true); // Clean (erase) the output buffer and turn off output buffering in case there was anything up in there to begin with. ob_end_clean(); // Turn on output buffering, because ... we just turned it off ... if it was on. ob_start(); echo $body; // Return the length of the output buffer $size = ob_get_length(); // send headers to tell the browser to close the connection // remember, the headers must be called prior to any actual // input being sent via our flush(es) below. header("Connection: close\r\n"); header("Content-Encoding: none\r\n"); header("Content-Length: $size"); // Set the HTTP response code // this is only available in PHP 5.4.0 or greater http_response_code($responseCode); // Flush (send) the output buffer and turn off output buffering ob_end_flush(); // Flush (send) the output buffer // This looks like overkill, but trust me. I know, you really don't need this // unless you do need it, in which case, you will be glad you had it! @ob_flush(); // Flush system output buffer // I know, more over kill looking stuff, but this // Flushes the system write buffers of PHP and whatever backend PHP is using // (CGI, a web server, etc). This attempts to push current output all the way // to the browser with a few caveats. flush(); }
  21. While PDO is "way better", it is also "way easier". Wow your professor, and try the following. The "?" are being replaced by the values in the array. There are different ways you can pass the values, and different ways to control what is returned, but this will give you the general idea. Have fun! <?php $db=new PDO("mysql:host=localhost;dbname=yourdatabase;charset",'yourusername','yourpassword'); $stmt=$db->prepare("select * from users where first_name like ? || last_name like ?"); $s='%'.$_POST['search'].'%'; $stmt->execute([$s,$s]); $results=$stmt->fetchAll(); echo('<pre>'.print_r($results,1).'</pre>');
  22. I know you think the file is there, but I would bet 10-to-1 odds that it isn't where you think it is. Are you attempting to access it from a file located in a different directory? When in doubt, try absolute file paths.
  23. For some reason, I though NULL and arithmetic resulted in NULL with PHP. Maybe I was thinking JavaScript, so I tested it, but it was the same as PHP. Then I tried MySQL, and found it was what I was thinking. Glad I wasn't going totally crazy. So.... Other than using a condition to check if null along with a ternary, what is the best way to return NULL if any of the arguments are NULL? <?php $x=null; $y=1; var_dump($x*$y); //results in 0, but wanted NULL var_dump($x+$y); //results in 1, but wanted NULL
  24. How can create $string='{"foo":123,"a1":[{"x":321,"y":{"a":5,"b":"hello"}},{"x":321,"y":{"a":2,"c":"goodby"}},{"x":321,"y":{"a":5,"b":"hi","d":"please"}}]}' given $a2? I would rather not convert all the individual JSON strings to an array or object first, and then convert it all back to JSON. Maybe another option (yikes!) is manually creating the JSON string? Note that foo will always be an integer. <?php $a1=[ ['x'=>321,'y'=>'{"a":5,"b":"hello"}'], ['x'=>321,'y'=>'{"a":2,"c":"goodby"}'], ['x'=>321,'y'=>'{"a":5,"b":"hi","d":"please"}'] ]; $a2=['foo'=>123,'a1'=>$a1]; print_r($a2); echo(json_encode($a2)."\n"); echo(json_encode($a2,JSON_UNESCAPED_SLASHES)."\n"); echo(json_encode($a2,JSON_UNESCAPED_UNICODE)."\n"); echo(json_encode($a2,JSON_UNESCAPED_SLASHES,1)."\n"); echo(json_encode($a2,JSON_UNESCAPED_UNICODE,1)."\n"); echo(json_encode($a2,JSON_UNESCAPED_SLASHES,2)."\n"); echo(json_encode($a2,JSON_UNESCAPED_UNICODE,2)."\n"); echo(json_encode($a2,JSON_UNESCAPED_SLASHES,3)."\n"); echo(json_encode($a2,JSON_UNESCAPED_UNICODE,3)."\n"); OUTPUT Array ( [foo] => 123 [a1] => Array ( [0] => Array ( [x] => 321 [y] => {"a":5,"b":"hello"} ) [1] => Array ( [x] => 321 [y] => {"a":2,"c":"goodby"} ) [2] => Array ( [x] => 321 [y] => {"a":5,"b":"hi","d":"please"} ) ) ) {"foo":123,"a1":[{"x":321,"y":"{\"a\":5,\"b\":\"hello\"}"},{"x":321,"y":"{\"a\":2,\"c\":\"goodby\"}"},{"x":321,"y":"{\"a\":5,\"b\":\"hi\",\"d\":\"please\"}"}]} {"foo":123,"a1":[{"x":321,"y":"{\"a\":5,\"b\":\"hello\"}"},{"x":321,"y":"{\"a\":2,\"c\":\"goodby\"}"},{"x":321,"y":"{\"a\":5,\"b\":\"hi\",\"d\":\"please\"}"}]} {"foo":123,"a1":[{"x":321,"y":"{\"a\":5,\"b\":\"hello\"}"},{"x":321,"y":"{\"a\":2,\"c\":\"goodby\"}"},{"x":321,"y":"{\"a\":5,\"b\":\"hi\",\"d\":\"please\"}"}]} {"foo":123,"a1":[{"x":321,"y":"{\"a\":5,\"b\":\"hello\"}"},{"x":321,"y":"{\"a\":2,\"c\":\"goodby\"}"},{"x":321,"y":"{\"a\":5,\"b\":\"hi\",\"d\":\"please\"}"}]} {"foo":123,"a1":[{"x":321,"y":"{\"a\":5,\"b\":\"hello\"}"},{"x":321,"y":"{\"a\":2,\"c\":\"goodby\"}"},{"x":321,"y":"{\"a\":5,\"b\":\"hi\",\"d\":\"please\"}"}]}
  25. If only... Have you seen this topic in the manual?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.