Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


kicken last won the day on July 9

kicken had the most liked content!

Community Reputation

494 Excellent

1 Follower

About kicken

  • Rank
    Wiser? Not exactly.

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    Bonita, FL
  • Age

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. As an aside that's related to your end goal, if you want to be able to cache/specify the state of external resources for testing, then the ideal thing to do is make sure you have a service that is responsible for fetching those resources, then create a mock version of that service that can return what you want instead of actually fetching the resource. For example, if you're contacting an API that returns the current weather and want to use that to get the current temperature you're code may look like: interface WeatherService { public function getCurrentConditions(string $location) : WeatherConditions; } class WeatherConditions { public $currentTemperature; public $windSpeed; public function __construct($temp, $wind){ $this->currentTemperature = $temp; $this->windSpeed = $wind; } } class MyController { private $weatherService; public function __construct(WeatherService $weather){ $this->weatherService = $weather; } public function whatIsTheWeather(){ $conditions = $this->weatherService->getCurrentConditions($_GET['location']); return sprintf('It is currently %0.2f degrees outside with wind moving at %0.2f mph' , $conditions->currentTemperature, $conditions->windSpeed); } } For your production code, you'd have an implementation of WeatherService that reaches out to your API endpoint to get the actual current conditions for the given location. For testing however, you can make a simple mock object that returns static data and inject that instead of your real service. For example: class MockWeatherService implements WeatherService { private $conditions = []; public function __construct(){ $this->conditions = [ 'london' => new WeatherConditions(72,7) , 'new york' => new WeatherConditions(82, 5) , 'san diego' => new WeatherConditions(67, 10) , 'paris' => new WeatherConditions(7, 12) ]; } public function getCurrentConditions(string $location) : WeatherConditions{ if (isset($this->conditions[$location])){ return $this->conditions[$location]; } throw new \RuntimeException('Location not found'); } } That way you don't need do anything particularly special in your code to be able to test it with static data. Instead all you do is adjust your dependency injection configuration to inject the mock service instead of the real service.
  2. Any particular reason for using JS instead of simple HTML validation? <input type="number" min="100000" max="999999"> (Assuming 000000 is invalid)
  3. In this code: $sql=mysqli_query($con,"SELECT * FROM invoice_items as d inner JOIN items as c ON d.itemnum=c.itemnum where invnumber = $id"); $row = mysqli_fetch_array($sql); $invno = $row['invnumber']; $itemnum = $row['itemnum']; $price = $row['price']; $quantity = $row['quantity']; $i = 0; // Establish the output variable $dyn_table = '<table class = "stripe" border = "1" cellpadding="10">'; $dyn_table .= '<tr><td class = "gridtext">' ."<b>Item Number</b>" . '</td>'; $dyn_table .= '<td class = "gridtext">' ."<b>Description</b>" . '</td>'; $dyn_table .= '<td class = "gridtext">' ."<b>Qty</b>" . '</td>'; $dyn_table .= '<td class = "gridtext">' ."<b>Price</b>" . '</td>'; while($row = mysqli_fetch_array($sql)){; $itemnum = $row['itemnum']; $title = $row['title']; $price = $row['price']; $quantity = $row['quantity']; $dyn_table .= '<tr><td>' . $itemnum . '</td>'; $dyn_table .= '<td>' . $title . '</td>'; $dyn_table .= '<td>' . $quantity . '</td>'; $dyn_table .= '<td>' . $price . '</td>'; $i++; } You're fetching the first row on line 3, then your while loop later on fetches rows 2...n. You probably want to just remove the fetch on line 3 and the variables you're trying to grab from it.
  4. You need to click the push-pin like icon in the upper right corner. Having that active makes the window sticky so it stays on the screen.
  5. kicken

    stuck block

    You need to specify your units for the margin values. 161px, not just 161.
  6. You don't have to specify the columns in your insert in the same order they exist in the table if that's what you mean. You can even leave columns out entirely if they have a default value or can be NULL. All that matters is that the values match up with the appropriate columns in the two lists. As far as placeholders go, if you're using :name style then order doesn't mater. If you're just using ? then order maters.
  7. You can't chain prepare and exec like that for a query where you want results. execute() returns a boolean, true if it succeeded or false if it failed. To get the results you have to call fetch on the statement object that is returned by prepare. As such, you have to assign the result of prepare, then call the execute method separately. <?php include '../includes/dbconn.inc'; $player = $link->prepare("SELECT * FROM players WHERE PlayerID=?"); $player->execute(['1']); var_dump($player->fetch());
  8. In the cases where PHP uses bit masks, they are used for just one particular call or as part of the constructor as you noticed. There's no trying to merge defaults with call specific options because that does't work. It seems like in your original post the goal was to be able to do something like: $o = JsonValidator::create(JsonValidator::STRICTMODE); $o->validate($input, $rules, JsonValidator::SETDEFAULT); //Keep strict mode and add additional SETDEFAULT option. //Same as above but this time disable strict mode? Can't be done $o->validate($input, $rules, JsonValidator::SETDEFAULT); That's simply not possible with bit mask values because as noted, there's no way to distinguish between 'strict mode not specified' and 'strict mode disabled' The only way to really have your flags be specified in both the constructor and in specific methods would be if you design it such that the flags specified in the constructor are always on and cannot be disabled later in a specific method call. Then in your call you could just do public function validate($input, $rules, $options = 0){ //Merge in constructor defaults. $options = $this->defaultOptions | $options; //... }
  9. You can't. There's no such thing as "those bits were not provided" really. A number is always 32/64 bits in length. All bits start as 0 then you explicitly turn on the ones you want to make a given number. Bit masks don't work well in this type of situation. A better solution is just to use an array of options.
  10. Might be caused by this bug: Scalar types is treated like class references until reparse Try invalidating the cache and see if that resolves it.
  11. Yea, pretty much. If you move the addPeriodicTimer call above the on call then you wouldn't need to pass by reference.
  12. What versions of the various react/* packages are you using exactly? Run composer info to find out. Based on the backtrace it seems you are probably using react/event-loop v0.4.3, and I'm guessing the other packages you have are from around the same time frame. I downgraded my install to react/socket v0.7.2 and whatever secondary packages match that release and was able to encounter some instances where a client would connect then immediately disconnect causing various errors to be returned by s_client. I suspect you're hitting this issue: Only close stream when the we reached end of the stream. Try updating your react requirements to their latest versions and see if that resolves your issues.
  13. The -fips suffix has me wondering if there's a difference that could be causing issues. Seems unlikely, but wouldn't hurt to get updated to the latest version. If that's not possible via the system package manager then compiling your own copy would be necessary. You might have to re-compile PHP, or at least the openssl extension to make it use the updated version. It's been a long time since I compiled my own versions of either so I'm not certain. Seems unlikely to be a memory related issue, and if the php code works then you should have all the modules you need. If you didn't you'd have undefined function errors.
  14. The memory_limit setting won't affect how much memory a script uses, just how much it's allowed to use. As such it doesn't have any direct effect on memory_get_usage. The difference between memory_get_usage() and memory_get_usage(true) is whether you're looking at PHP's internal memory pool or the total memory allocated to the process by the OS. When PHP allocates memory from the OS it generally doesn't return it to the OS when it's done, it just marks it free internally and re-uses it in the future. Are you encountering issues with they very first connection to your server, or is it only after a period of time that the errors occur and/or it crashes due to memory limits? You do have one memory leak in your sample server above with the periodic timer, but it'd take time and a lot of connections for that to build up to a problem. To solve that, you need to cancel your timers when the connection is closed. /** @var TimerInterface $timer */ $timer = null; $connection->on('close', function() use (&$timer, $loop){ echo("onClose" . PHP_EOL); $loop->cancelTimer($timer); }); $timer = $loop->addPeriodicTimer(1, function ($timer) { $data='Hello!'; memory(); });
  15. Mine is 512MB. I'd guess there's a memory leak in your code somewhere. Lots of little packets will eventually add up if your storing them forever. I'd say look over the code and make sure you're not holding on to things longer than needed. For example, make sure when a client disconnects you clean up the resources for it instead of just letting it linger in an array or whatever. If you want to post or PM me your code I can look over it and see if I spot anything.
  • 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.